protected function handle_file($file) { $up_tmp_name = $file['tmp_name'][$this->file_column]; $new_name = $file['name'][$this->file_column]; $destination = WAX_ROOT . $this->file_base; /* CHANGED - set it so its just the file_base added to db */ $this->{$this->path_column} = $this->file_base; $this->{$this->type_column} = $file['type'][$this->file_column]; $this->{$this->file_column} = File::safe_file_save($destination, $new_name); $destination = $destination . $this->{$this->file_column}; if (move_uploaded_file($up_tmp_name, $destination)) { chmod($destination, 0777); } }
public function copy() { if ($id = Request::get('id')) { $this->model = new $this->model_class($id); $copy_file = File::safe_file_save(PUBLIC_DIR . $this->model->rpath . "/", $this->model->filename); $full_copy_file = PUBLIC_DIR . $this->model->rpath . "/" . $copy_file; $file = PUBLIC_DIR . $this->model->rpath . "/" . $this->model->filename; copy($file, $full_copy_file); $fs = new CmsFilesystem(); $fs->databaseSync(PUBLIC_DIR . $this->model->rpath, $this->model->rpath); $copy = new $this->model_class(); $copy = $copy->filter(array("rpath" => $this->model->rpath, "filename" => $copy_file))->first(); $this->redirect_to("/admin/files/edit/" . $copy->id); } }
public function save_file($up_tmp_name, $file) { $file_destination = WAX_ROOT . $this->file_root . File::safe_file_save(WAX_ROOT . $this->file_root, $file); //if(move_uploaded_file($up_tmp_name, $file_destination) ) chmod($file_destination, 0777); if (rename($up_tmp_name, $file_destination)) { chmod($file_destination, 0777); } else { return false; } return $file_destination; }
function uploadSmart() { $uploadDir = $this->uploadDir; if (!file_exists($uploadDir . "stats_" . session_id() . ".txt")) { $this->jsonStart(); $this->jsonAdd("\"percent\": 0, \"percentSec\": 0, \"speed\": \"0\", \"secondsLeft\": \"0\", \"done\": \"false\""); echo $this->jsonReturn("bindings"); exit; } $lines = file($uploadDir . "stats_" . session_id() . ".txt"); $this->jsonStart(); $percent = round($lines[0] / 100, 3); $percentSec = round($lines[1] / 100, 4); $speed = $this->filesize_format($lines[2]) . 's'; $secondsLeft = $this->secs_to_string(round($lines[3])); $size = $this->filesize_format($lines[4]) . 's'; if ($percent == 1) { // cleanup time if (isset($_SESSION['uploadPath'])) { $path = $_SESSION['uploadPath']; $userpath = $this->defaultFileStore . $path; $sessionid = session_id(); $dh = opendir($uploadDir); while (($file = readdir($dh)) !== false) { $sessionlen = strlen(session_id()); if (substr($file, 0, $sessionlen) == session_id()) { $filename = substr($file, $sessionlen + 1); $uploadfile = File::safe_file_save($uploadDir, $filename); $i = 1; while (file_exists($userpath . '/' . $uploadfile)) { $uploadfile = $i . '_' . $filename; $i++; } if (!rename($uploadDir . $file, $userpath . "/" . $uploadfile)) { echo "Error"; } } } closedir($dh); if (file_exists($uploadDir . "stats_" . session_id() . ".txt")) { unlink($uploadDir . "stats_" . session_id() . ".txt"); } if (file_exists($uploadDir . "temp_" . session_id())) { unlink($uploadDir . "temp_" . session_id()); } } $done = "true"; } else { $done = "false"; } $this->jsonAdd("\"percent\": {$percent}, \"size\": \"{$size}\",\"percentSec\": {$percentSec}, \"speed\": \"{$speed}\", \"secondsLeft\": \"{$secondsLeft}\", \"done\": \"{$done}\""); echo $this->jsonReturn("bindings"); }
public function file_upload() { if ($url = $_POST["upload_from_url"]) { $str = ""; foreach ($_POST as $k => $v) { $str .= "{$k}:{$v}\n"; } WaxLog::log('error', 'running...' . $str); $path = $_POST['wildfire_file_folder']; $fs = new CmsFilesystem(); $filename = basename($url); $ext = strtolower(array_pop(explode(".", $filename))); if ($_POST["wildfire_file_filename"]) { $filename = $_POST["wildfire_file_filename"] . "." . $ext; } $filename = $_POST["wildfire_file_filename"] = File::safe_file_save($fs->defaultFileStore . $path, $filename); $file = $fs->defaultFileStore . $path . "/" . $filename; $handle = fopen($file, 'x+'); fwrite($handle, file_get_contents($url)); fclose($handle); $fname = $fs->defaultFileStore . $path . "/" . $filename; chmod($fname, 0777); $dimensions = getimagesize($fname); if (AdminFilesController::$max_image_width && $dimensions[0] > AdminFilesController::$max_image_width) { $flag = File::resize_image($fname, $fname, AdminFilesController::$max_image_width, false, true); if (!$flag) { WaxLog::log('error', '[resize] FAIL'); } } $fs->databaseSync($fs->defaultFileStore . $path, $path); $file = new WildfireFile(); $newfile = $file->filter(array("filename" => $filename, "rpath" => $path))->first(); $newfile->description = $_POST["wildfire_file_description"]; $newfile->save(); //if these are set then attach the image to the doc! if (Request::post('content_id') && Request::post('model_string') && Request::post('join_field')) { $model_id = Request::post('content_id'); $class = Inflections::camelize(Request::post('model_string'), true); $field = Request::post('join_field'); $model = new $class($model_id); $model->{$field} = $newfile; } echo "Uploaded"; } elseif ($_FILES) { error_log("Starting File upload"); error_log(print_r($_POST, 1)); $path = $_POST['wildfire_file_folder']; $fs = new CmsFilesystem(); $_FILES['upload'] = $_FILES["Filedata"]; $_FILES['upload']['name'] = str_replace(' ', '', $_FILES['upload']['name']); $fs->upload($path); $fs->databaseSync($fs->defaultFileStore . $path, $path); $fname = $fs->defaultFileStore . $path . "/" . $_FILES['upload']['name']; if ($dimensions = getimagesize($fname)) { if ($dimensions[2] == "7" || $dimensions[2] == "8") { WaxLog::log("error", "Detected TIFF Upload"); $command = "mogrify " . escapeshellcmd($fname) . " -colorspace RGB -format jpg"; system($command); $newname = str_replace(".tiff", ".jpg", $fname); $newname = str_replace(".tif", ".jpg", $newname); rename($fname, $newname); } } chmod($fname, 0777); $file = new WildfireFile(); $newfile = $file->filter(array("filename" => $_FILES['upload']['name'], "rpath" => $path))->first(); $newfile->description = $_POST["wildfire_file_description"]; $newfile->save(); //if these are set then attach the image to the doc! if (Request::post('content_id') && Request::post('model_string') && Request::post('join_field')) { $model_id = Request::post('content_id'); $class = Inflections::camelize(Request::post('model_string')); $field = Request::post('join_field'); $model = new $class($model_id); $model->{$field} = $newfile; } echo "Uploaded"; } else { die("UPLOAD ERROR"); } exit; }