/** * Uploads all files in a specific form * @param string $form_name_id The id/name of the form * @param string $input_name The input name of the input file * @return array ["original_filename", "extension", "fullpath] File info of the uploaded file */ public static function UploadFormFiles($form_name_id, $input_name) { //Get the inputs of type=file $inputs = SystemQueries::GetFormInputsFileType($form_name_id, $input_name); //Set file info for return $files; // = array(); //Loop through input type=file foreach ($inputs as $input) { // No file has been selected for upload if ($_FILES[$input->input_name]['error'] == UPLOAD_ERR_NO_FILE || $_FILES[$input->input_name]['size'] == 0) { $files = array("original_filename" => null, "extension" => null, "fullpath" => null); //No file selected //Set the file link to the post object $_POST[$input->input_name] = null; } else { if ($_FILES[$input->input_name]['error'] != UPLOAD_ERR_OK || $_FILES[$input->input_name]["error"] > 0 || empty($_FILES[$input->input_name]["name"]) || empty($_FILES[$input->input_name]["tmp_name"])) { Logger::File(); RequestManager::RequestError(); //Error on upload } else { if (is_uploaded_file($_FILES[$input->input_name]["tmp_name"]) && $_FILES[$input->input_name]['error'] == UPLOAD_ERR_OK) { if (trim($input["input_attributes"]) != "" || self::IsFileWithExpectedExtension($input) || self::IsFileWithExpectedMimeType($input)) { // Default web root directory definition with the new folder defined in the argument $web_server_directory = $_SERVER['DOCUMENT_ROOT'] . "/uploads"; if (!self::CreatePath($web_server_directory)) { Logger::File(); RequestManager::RequestError(); //Error creating the file directory; } $full_path = self::file_directory($web_server_directory, $input->input_name); // Saves the uploaded file if (move_uploaded_file($_FILES[$input->input_name]["tmp_name"], $full_path)) { //Renames the current uploaded file for uniqueness $fullpath = self::file_name_generator($web_server_directory, $input); if (rename($full_path, $fullpath)) { $files = array("original_filename" => $_FILES[$input->input_name]["name"], "extension" => self::GetUploadedFileExtension($input), "fullpath" => $fullpath); //Set the file link to the post object $_POST[$input->input_name] = $fullpath; } else { Logger::File(); RequestManager::RequestError(); //Error on file directory or directory doesn't exist, upload failed } } else { Logger::File(); RequestManager::RequestError(); //Error moving file to the specified directory or directory doesn't exist } } else { Logger::File(); RequestManager::RequestError(); //File type not allowed upload failed } } } } } return $files; }