public function exitEditor() { //eDebug($this->params,true); switch ($this->params['exitType']) { case 'saveAsCopy': $oldimage = new expFile($this->params['fid']); $copyname = expFile::resolveDuplicateFilename($oldimage->path); copy(BASE . $this->cacheDir . "/" . $this->params['cpi'], $oldimage->directory . $copyname); //copy the edited file over to the files dir $newFile = new expFile(array("filename" => $copyname)); //construct a new expFile $newFile->directory = $oldimage->directory; $newFile->title = $oldimage->title; $newFile->shared = $oldimage->shared; $newFile->mimetype = $oldimage->mimetype; $newFile->posted = time(); $newFile->filesize = filesize(BASE . $this->cacheDir . "/" . $this->params['cpi']); $resized = getimagesize(BASE . $this->cacheDir . "/" . $this->params['cpi']); $newFile->image_width = $resized[0]; $newFile->image_height = $resized[1]; $newFile->alt = $oldimage->alt; $newFile->is_image = $oldimage->is_image; $newFile->save(); //Save it to the database break; case 'saveAsIs': //eDebug($this->params,true); $oldimage = new expFile($this->params['fid']); $resized = getimagesize(BASE . $this->cacheDir . "/" . $this->params['cpi']); $oldimage->image_width = $resized[0]; $oldimage->image_height = $resized[1]; $oldimage->save(); copy(BASE . $this->cacheDir . "/" . $this->params['cpi'], $oldimage->directory . $oldimage->filename); //copy the edited file over to the files dir break; default: # code... break; } // proper file types to look for $types = array(".jpg", ".gif", ".png"); //Pixidou images directory, the editor's cache $cachedir = BASE . $this->cacheDir; if (is_dir($cachedir) && is_readable($cachedir)) { $dh = opendir($cachedir); while (($tmpfile = readdir($dh)) !== false) { if (in_array(substr($tmpfile, -4, 4), $types)) { $filename = $cachedir . $tmpfile; unlink($filename); } } } redirect_to(array("controller" => 'file', "action" => 'picker', "ajax_action" => 1, "update" => $this->params['update'], "fck" => $this->params['fck'])); }
/** * File UPLOAD that also inserts File info into database. * * File UPLOAD is a straight forward uploader and processor. It can accept * filename and destination directory overrides as well. It has an additional * pair of flags that allow for an upload NOT to be inserted into the database * (default to INSERT) and if it previous file, with the same name, should be * overwritten (default to NO overwrite) * * @static * @access public * * @uses class|method|global|variable description * @requires class_name * * @PHPUnit Not Defined|Implement|Completed * * @param string $_postName The name of the _FILE upload array * @param bool|string $_force Force the uploaded to overwrite existing file of same name * @param bool|string $_save Save file info to database, defaults to TRUE * @param string $_destFile Override the uploaded file name * @param string $_destDir Override the default FILE UPLOAD location * * @return object $_objFile expFile Object * @return object $errMsg Error message if something failed@throws void * * @TODO Have file upload overwrite make sure not to duplicate its record in the DB * */ public static function fileUpload($_postName = null, $_force = false, $_save = true, $_destFile = null, $_destDir = null) { // Make sure something was sent first off... if (!isset($_SERVER['CONTENT_TYPE']) || strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== 0) { return 'bad upload form'; } //check for errors switch ($_FILES[$_postName]['error']) { case UPLOAD_ERR_OK: // Everything looks good. Continue with the update. break; case UPLOAD_ERR_INI_SIZE: // case images: // This is a tricky one to catch. If the file is too large for // POST, then the script won't even run. // But if its between post_max_size and upload_max_filesize, // we will get here. return 'file_too_large'; case UPLOAD_ERR_FORM_SIZE: return 'file_exceeds_form_MAX_FILE_SIZ'; case UPLOAD_ERR_PARTIAL: return 'partial_file'; case UPLOAD_ERR_NO_FILE: return 'no_file_uploaded'; case UPLOAD_ERR_NO_TMP_DIR: return 'missing_tmp_folder'; case UPLOAD_ERR_CANT_WRITE: return 'failed_write_to_disk'; case UPLOAD_ERR_EXTENSION: return 'upload_stopped_by_extension'; default: return 'unknown'; break; } // If $_destDir is not defined, use the default Files directory // $_destDir = ( $_destDir == null ) ? UPLOAD_DIRECTORY : $_destDir; $_destDir = $_destDir == null ? UPLOAD_DIRECTORY_RELATIVE : $_destDir; // If $_destFile is defined, use that name as an override for the // uploaded file name $_destFile = $_destFile == null ? self::fixFileName($_FILES[$_postName]['name']) : $_destFile; // Fix the filename, so that we don't have funky characters screwing // with our attempt to create the destination file. // $_destFile = self::fixFileName( $_FILES[$_postName]['name']); // eDebug($_destFile,1); // Build destination fille path for future use $_destFullPath = BASE . $_destDir . $_destFile; //if the file exists and we don't want to overwrite it, create a new one if (file_exists($_destFullPath) && $_force == false) { $_destFile = self::resolveDuplicateFilename($_destFullPath); $_destFullPath = $_destDir . $_destFile; } //Check to see if the directory exists. If not, create the directory structure. // if (!file_exists(BASE . $_destDir)) { // self::makeDirectory(BASE . $_destDir); // } // Move the temporary uploaded file into the destination directory, // and change the name. move_uploaded_file($_FILES[$_postName]['tmp_name'], $_destFullPath); if (file_exists($_destFullPath)) { $__oldumask = umask(0); chmod($_destFullPath, FILE_DEFAULT_MODE); umask($__oldumask); // Checking if ($__oldumask != umask()) { flash('error', gt('An error occurred while setting file permissions') . ': ' . $_destFullPath); } } else { return 'could not move'; } // At this point, we are good to go. // Create a new expFile Object for further processing $_fileParams = array('filename' => $_destFile, 'directory' => $_destDir); $_objFile = new expFile($_fileParams); // Insert new File Record if ($_save === true) { $_objFile->save(); } return $_objFile; }
public function editShare() { global $user; $file = new expFile($this->params['id']); if (!isset($this->params['newValue'])) { $this->params['newValue'] = 0; } if ($user->id == $file->poster || $user->is_acting_admin == 1) { $file->shared = $this->params['newValue']; $file->save(); $ar = new expAjaxReply(200, gt('This file is now shared.'), $file); } else { $ar = new expAjaxReply(300, gt("You didn't create this file, so it's not yours to share.")); } $ar->send(); echo json_encode($file); }