public function handle_file_upload($uploadedFile, $index) { $tmpName = $uploadedFile["tmp_name"]; $name = $uploadedFile["name"]; $size = $uploadedFile["size"]; $type = $uploadedFile["type"]; $error = $uploadedFile["error"]; $fileInfo = array("name" => $name, "size" => intval($size), "type" => $type, "isThumbnail" => false); $uploadDir = $this->pSet->getFinalUploadFolder($this->field, $fileInfo); $uploadDirRelative = $this->pSet->getUploadFolder($this->field, $fileInfo); $file = array(); $file["error"] = false; $file["name"] = trim_file_name($name, $type, $index, $this); $file["usrName"] = $file["name"]; $file["size"] = intval($size); switch ($type) { case "image/png": case "image/x-png": $file["type"] = "image/png"; break; case "image/jpeg": case "image/pjpeg": $file["type"] = "image/jpeg"; break; default: $file["type"] = $type; } $path_parts = $this->pathinfo_local($name); if ($file["type"] == "") { $file["type"] = getContentTypeByExtension($path_parts["extension"]); } $file["isImg"] = false; $file["thumbnail"] = ""; if ($this->pSet->isMakeDirectoryNeeded($this->field)) { if (!makeSurePathExists($uploadDir)) { $file["error"] = "Upload folder doesn't exist"; return $file; } } else { if (!is_dir($uploadDir)) { $file["error"] = "Upload folder doesn't exist"; return $file; } } if ($this->validate($uploadedFile, $file, $error, $size, $index, $uploadDir)) { $file["isImg"] = CheckImageExtension($tmpName) != false; $this->handle_form_data($file, $index); $file["name"] = $this->tempnam_sfx($uploadDir, $path_parts["filename"], $path_parts["extension"]); $file_path = $uploadDir . $file["name"]; clearstatcache(); upload_File($uploadedFile, $file_path); $file_size = filesize($file_path); if ($this->options["resizeOnUpload"]) { $tempOptions = array('max_width' => $this->options["max_width"], 'max_height' => $this->options["max_width"]); $new_file_name = $this->tempnam_sfx($uploadDir, $path_parts["filename"], $path_parts["extension"]); if ($this->create_scaled_image($uploadDir . $file["name"], $uploadDir, $new_file_name, $tempOptions, $file, false, $uploadDirRelative, $uploadedFile)) { unlink($file_path); $file["name"] = $new_file_name; $file_path = $uploadDir . $new_file_name; $file_size = filesize($file_path); } } if ($file_size === $file["size"]) { $file["url"] = $uploadDir . rawurlencode($file["name"]); foreach ($this->options['image_versions'] as $version => $options) { $fileInfoThimbnail = array("name" => $name, "size" => intval($size), "type" => $type, "isThumbnail" => true); $thumbUploadDir = $this->pSet->getFinalUploadFolder($this->field, $fileInfoThimbnail); $thumbUploadDirRelative = $this->pSet->getUploadFolder($this->field, $fileInfoThimbnail); if ($this->pSet->isMakeDirectoryNeeded($this->field)) { if (!makeSurePathExists($thumbUploadDir)) { continue; } } $thumbnail_name = $this->tempnam_sfx($thumbUploadDir, $options['thumbnailPrefix'] . $path_parts["filename"], $path_parts["extension"]); if ($this->create_scaled_image($uploadDir . $file["name"], $thumbUploadDir, $thumbnail_name, $options, $file, true, $thumbUploadDirRelative, $uploadedFile)) { clearstatcache(); $file_size = filesize($file_path); } } } else { unlink($file_path); $file["error"] = 'abort'; } $file["size"] = $file_size; $file["name"] = $uploadDirRelative . $file["name"]; $this->set_file_delete_url($file); } return $file; }
if (postvalue("importType") == "text") { $importText = postvalue("importText"); $returnJSON["previewData"] = $pageObject->getPreviewDataFromText($importText); // prepare the temp file path $rnrTempImportFilePath = getabspath("templates_c/" . $rnrTempFileName . ".csv"); // save file in a temporary directory runner_save_textfile($rnrTempImportFilePath, $importText); } else { $ext = getImportFileExtension("importFile" . $id); $importTempFileName = getTempImportFileName("importFile" . $id); $returnJSON["previewData"] = $pageObject->getPreviewDataFromFile($importTempFileName, $ext); // save file in a temporary directory $importFileData = getImportFileData("importFile" . $id); // prepare the temp file path $rnrTempImportFilePath = getabspath("templates_c/" . $rnrTempFileName . "." . $ext); upload_File($importFileData, $rnrTempImportFilePath); } // keep the temporary path in the SESSION variable $_SESSION[$pageObject->sessionPrefix . "_tempImportFilePath"] = $rnrTempImportFilePath; echo printJSON($returnJSON, postvalue("useXHR")); exit; } if ($action == "importData") { if ($eventObj->exists('BeforeImport')) { if ($eventObj->BeforeImport($pageObject) === false) { echo printJSON(array()); exit(0); } } $rnrTempImportFilePath = $_SESSION[$pageObject->sessionPrefix . "_tempImportFilePath"]; $importData = my_json_decode(postvalue("importData"));