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;
 }
Esempio n. 2
0
 /**
  * Special conversion function - takes the details in the old cms switches it over the the new cms
  **/
 public function port_ids()
 {
     $file = new CmsFile();
     $files = $file->find_all();
     foreach ($files as $file) {
         $new = new WildfireFile();
         $s_path = rtrim(str_replace("public/", "", strrchr($file->path, "public/files")), "/");
         $new_file = $new->filter("filename = '{$file->filename}' AND rpath LIKE '%{$s_path}%'")->first();
         if ($new_file->id) {
             $new_file->oldid = $file->id;
             $new_file->description = $file->caption;
             $new_file->save();
         }
     }
     exit;
 }
Esempio n. 3
0
 public function flash_files()
 {
     $model = new WildfireFile();
     return $model->filter("`filename` LIKE '%.swf'")->all();
 }