Exemple #1
0
 /**
  * you pass this function the key for the $_FILES[key] array
  * and the new filepath to move the file to
  * then add the new filename
  * if $createPath is true then this will attempt to create the directories required for the path
  *
  * @param string $key
  * @param string $path
  * @param string $filename
  * @param bool $createPath
  */
 public function upload($key, $path, $filename = false, $createPath = true, $permissions = '777')
 {
     if (self::isUploaded($key)) {
         //default to the name on the client machine
         if (!$filename) {
             $filename = $_FILES[$key]['name'];
         }
         $path = Digitalus_Toolbox_String::stripLeading('/', $path);
         if ($createPath) {
             //attempt to create the new path
             Digitalus_Filesystem_Dir::makeRecursive(self::PATH_TO_FILES, $path);
         }
         //clean the filename
         $filename = Digitalus_Filesystem_File::cleanFilename($filename);
         $filename = Digitalus_Toolbox_String::getSelfFromPath($filename);
         $fullPath = self::PATH_TO_FILES . "/" . $path . "/" . $filename;
         if (move_uploaded_file($_FILES[$key]['tmp_name'], $fullPath)) {
             // Set permissions for this file
             @chmod($fullPath, $permissions);
             //return the filepath if things worked out
             //this is relative to the site root as this is the format that will be required for links and what not
             $fullPath = Digitalus_Toolbox_String::stripLeading('./', $fullPath);
             return $fullPath;
         }
     }
 }
Exemple #2
0
 public static function upload($file, $path, $filename = null, $createPath = true, $base = '.')
 {
     $view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view;
     $e = new Digitalus_View_Error();
     if ($file['error'] == 4 || empty($file['name'])) {
         return;
     }
     if (self::isAllowed($file['type'])) {
         $path = self::getMediaPath($path);
         //default to the name on the client machine
         if (is_null($filename)) {
             $filename = $file['name'];
         }
         $filename = str_replace('_', '-', $filename);
         $filename = str_replace(' ', '-', $filename);
         $path = str_replace(self::rootDirectory(), '', $path);
         $path = Digitalus_Toolbox_String::stripUnderscores($path);
         $path = Digitalus_Toolbox_String::stripLeading('/', $path);
         /*
          * This fixes an issue when the system is installed on a path other than
          * root. Path should contain a path that is relative to the (cms) root
          * index.php (not root to the public_html of the web server (as it was trying
          * to do before).
          */
         $config = Zend_Registry::get('config');
         $path = $config->filepath->media . '/' . $path;
         if ($createPath) {
             //attempt to create the new path
             Digitalus_Filesystem_Dir::makeRecursive($base, $path);
         }
         //clean the filename
         $filename = Digitalus_Filesystem_File::cleanFilename($filename);
         $filename = basename($filename);
         $path .= '/' . $filename;
         if (move_uploaded_file($file['tmp_name'], $path)) {
             //return the filepath if things worked out
             //this is relative to the site root as this is the format that will be required for links and what not
             $fullPath = Digitalus_Toolbox_String::stripLeading($base . '/', $path);
             return $fullPath;
         } else {
             $e->add($view->getTranslation('An error occurred uploading the file' . ': ' . $file['name']));
         }
     } else {
         $e->add($view->getTranslation('This filetype is not allowed' . ': ' . $file['type']));
     }
 }
Exemple #3
0
 public static function upload($file, $path, $filename, $createPath = true, $base = '.')
 {
     if (self::isAllowed($file['type'])) {
         $path = self::getMediaPath($path);
         //default to the name on the client machine
         if ($filename == null) {
             $filename = $file['name'];
         }
         $filename = str_replace('_', '-', $filename);
         $filename = str_replace(' ', '-', $filename);
         $path = str_replace(self::rootDirectory(), '', $path);
         $path = Digitalus_Toolbox_String::stripUnderscores($path);
         $path = Digitalus_Toolbox_String::stripLeading('/', $path);
         /*
          * Update by Brad Seefeld on May 12, 2009
          *
          * This fixes an issue when the system is installed on a path other than
          * root. Path should contain a path that is relative to the (cms) root
          * index.php (not root to the public_html of the web server (as it was trying
          * to do before).
          */
         $config = Zend_Registry::get('config');
         $path = $config->filepath->media . '/' . $path;
         if ($createPath) {
             //attempt to create the new path
             Digitalus_Filesystem_Dir::makeRecursive($base, $path);
         }
         //clean the filename
         $filename = Digitalus_Filesystem_File::cleanFilename($filename);
         $filename = basename($filename);
         $path .= '/' . $filename;
         if (move_uploaded_file($file['tmp_name'], $path)) {
             //return the filepath if things worked out
             //this is relative to the site root as this is the format that will be required for links and what not
             $fullPath = Digitalus_Toolbox_String::stripLeading($base . '/', $path);
             return $fullPath;
         }
     }
 }