Example #1
0
             $json['error'] = _('Warning: Can not copy this file or directory!');
         }
         if (is_file($old_name)) {
             $ext = strrchr($old_name, '.');
         } else {
             $ext = '';
         }
         $new_name = dirname($old_name) . '/' . html_entity_decode($_POST['name'], ENT_QUOTES, 'UTF-8') . $ext;
         if (file_exists($new_name)) {
             $json['error'] = _('Warning: A file or directory with the same name already exists!');
         }
     } else {
         $json['error'] = _('Warning: Please select a directory or file!');
     }
     if (!isset($json['error'])) {
         $fileObject = Pommo_Filesystem_Item::factory($old_name);
         $fileObject->copy($new_name);
         $json['success'] = _('Success: Your file or directory has been copied!');
     }
     break;
     // Rename a file or directory
 // Rename a file or directory
 case 'rename':
     if (isset($_POST['path']) && isset($_POST['name'])) {
         if (mb_strlen($_POST['name']) < 3 || mb_strlen($_POST['name']) > 255) {
             $json['error'] = _('Warning: Filename must be a between 3 and 255!');
         }
         $old_name = rtrim(IMAGE_DIRECTORY . html_entity_decode($_POST['path'], ENT_QUOTES, 'UTF-8'), '/');
         if (!file_exists($old_name) || $old_name . '/' == IMAGE_DIRECTORY) {
             $json['error'] = _('Warning: Can not rename this directory!');
         }
 /**
  * Gets all file objects that are immediate sub-children of this directory
  * @return array|Pommo_Filesystem_File[]
  */
 public function getDirectoryFiles()
 {
     $files = glob(rtrim($this->_itemPath, '/') . '/*');
     $fileObjects = array();
     if ($files) {
         foreach ($files as $file) {
             $fileObject = Pommo_Filesystem_Item::factory($file);
             if ($fileObject instanceof Pommo_Filesystem_File) {
                 $fileObjects[] = $fileObject;
             }
         }
     }
     return $fileObjects;
 }