Example #1
0
 public static function delete_file() {
   MPC::incl("files");
   MPC_Files::delete_file();
 }
Example #2
0
    /**
     * Returns array('success'=>true) or array('error'=>'error message')
     */
    function handleUpload() { 
      $dir = $this->options["dir"];
      
        if (!is_writable($dir)){
          return array('error' => "Sorry, the file could not be uploaded as the upload directory isn't writable.");
        }
        
        if (!$this->file){
            return array('error' => __('No files were uploaded.', MASTERPRESS_DOMAIN));
        }
        
        $size = $this->file->getSize();
        
        if ($size == 0) {
            return array('error' => 'File is empty');
        }
        
        if ($size > $this->options["size_limit"]) {
            return array('error' => sprintf( __('Sorry, the file is too large. The maximum size allowed is %s bytes', MASTERPRESS_DOMAIN), $this->options["size_limit"]));
        }
        
        $pathinfo = pathinfo($this->file->getName());
        $filename = $pathinfo['filename'];
        //$filename = md5(uniqid());
        $ext = $pathinfo['extension'];

        if($this->options["allowed_extensions"] && !in_array(strtolower($ext), $this->options["allowed_extensions"])){
            $these = implode(', ', $this->options["allowed_extensions"]);
            return array('error' => sprintf( __('Sorry, you cannot upload a file of this type. Files must have an extension in the following list: %s.', MASTERPRESS_DOMAIN), $these) );
        }
            
        // traversal mod to allow serial numbering for non-replace
        $count = 0;
        
        // mod the file name based on options
        
        $v = ".v";
        
        $filename = MPC_Files::sanitize_filename($filename, $this->options);
        
        if (!isset($this->options["overwrite"])) {
          $basefilename = $filename;
        
          while (file_exists($dir . $filename . '.' . $ext)) {
            $count++;
            $filename = $basefilename.$v.$count;
          }
        }
      
        if ($this->file->save($dir . $filename . '.' . $ext)) {
          // traversal mod to return the eventual filename (why wasn't this included???)
            return array("dir" => $this->options["sub_dir"], 'success' => true, 'filename' => $filename . '.' . $ext);
        } else {
            return array('error'=> __('Could not save uploaded file.', MASTERPRESS_DOMAIN) .
                __('The upload was cancelled, or a server error has occurred.', MASTERPRESS_DOMAIN));
        }
        
    }