isWritable() public method

Checks if the directory is writable
public isWritable ( boolean $recursive = false ) : boolean
$recursive boolean
return boolean
 public function redactor__upload()
 {
     if (!Auth::getCurrentMember()) {
         exit("Invalid Request");
     }
     $path = Request::get('path');
     $is_image = Request::get('is_image');
     if (isset($path)) {
         $dir = Path::tidy(ltrim($path, '/') . '/');
         if (isset($_POST['subfolder'])) {
             $dir .= $_POST['subfolder'] . '/';
         }
         Folder::make($dir);
         $file_type = strtolower($_FILES['file']['type']);
         $file_info = pathinfo($_FILES['file']['name']);
         // pull out the filename bits
         $filename = $file_info['filename'];
         $ext = $file_info['extension'];
         // build filename
         $file = $dir . $filename . '.' . $ext;
         // check for dupes
         if (File::exists($file)) {
             $file = BASE_PATH . '/' . $dir . $filename . '-' . date('YmdHis') . '.' . $ext;
         }
         if (!Folder::isWritable($dir)) {
             Log::error('Upload failed. Directory "' . $dir . '" is not writable.', 'redactor');
             echo json_encode(array('error' => "Redactor: Upload directory not writable."));
             die;
         }
         if ($is_image && ($_FILES['file']['type'] == 'image/png' || $_FILES['file']['type'] == 'image/jpg' || $_FILES['file']['type'] == 'image/gif' || $_FILES['file']['type'] == 'image/jpeg')) {
             if (Request::get('resize', false)) {
                 $image = Image::make($_FILES['file']['tmp_name']);
                 $width = Request::get('width', null);
                 $height = Request::get('height', null);
                 $ratio = Request::get('ratio', true);
                 $upsize = Request::get('upsize', false);
                 $quality = Request::get('quality', '75');
                 $image->resize($width, $height, $ratio, $upsize)->save($file, $quality);
             } else {
                 move_uploaded_file($_FILES['file']['tmp_name'], $file);
             }
         } else {
             move_uploaded_file($_FILES['file']['tmp_name'], $file);
         }
         $return = array('filelink' => Path::toAsset($file));
         echo stripslashes(json_encode($return));
     } else {
         echo json_encode(array('error' => "Redactor: Upload directory not set."));
     }
 }
Esempio n. 2
0
 public function redactor__upload()
 {
     if (!Statamic_Auth::get_current_user()) {
         exit("Invalid Request");
     }
     $path = Request::get('path');
     if (isset($path)) {
         $dir = Path::tidy(ltrim($path, '/') . '/');
         if (isset($_POST['subfolder'])) {
             $dir .= $_POST['subfolder'] . '/';
         }
         Folder::make($dir);
         $_FILES['file']['type'] = strtolower($_FILES['file']['type']);
         if ($_FILES['file']['type'] == 'image/png' || $_FILES['file']['type'] == 'image/jpg' || $_FILES['file']['type'] == 'image/gif' || $_FILES['file']['type'] == 'image/jpeg') {
             $file_info = pathinfo($_FILES['file']['name']);
             // pull out the filename bits
             $filename = $file_info['filename'];
             $ext = $file_info['extension'];
             // build filename
             $file = $dir . $filename . '.' . $ext;
             // check for dupes
             if (File::exists($file)) {
                 $file = $dir . $filename . '-' . date('YmdHis') . '.' . $ext;
             }
             if (!Folder::isWritable($dir)) {
                 Log::error('Upload failed. Directory "' . $dir . '" is not writable.', 'redactor');
                 echo json_encode(array('error' => "Redactor: Upload directory not writable."));
                 die;
             }
             copy($_FILES['file']['tmp_name'], $file);
             // display file
             $array = array('filelink' => Config::getSiteRoot() . $file);
             echo stripslashes(json_encode($array));
         } else {
             echo json_encode(array('error' => "Redactor: Could not find directory: '{$dir}'"));
         }
     } else {
         echo json_encode(array('error' => "Redactor: Upload directory not set."));
     }
 }
Esempio n. 3
0
 /**
  * Upload a file.
  *
  * @param string  $file  Name of file
  * @param string  $target  target of file
  * @param string  $filename  Name of new file
  * @return bool
  **/
 public static function upload($file, $destination, $add_root_variable = false, $renamed_file = false)
 {
     Folder::make($destination);
     $info = pathinfo($file['name']);
     $extension = $info['extension'];
     $filename = $renamed_file ?: $info['filename'];
     // build filename
     $new_filename = Path::assemble(BASE_PATH, $destination, $filename . '.' . $extension);
     // check for dupes
     if (File::exists($new_filename)) {
         $new_filename = Path::assemble(BASE_PATH, $destination, $filename . '-' . date('YmdHis') . '.' . $extension);
     }
     // Check if destination is writable
     if (!Folder::isWritable($destination)) {
         Log::error('Upload failed. Directory "' . $destination . '" is not writable.', 'core');
         return null;
     }
     // write file
     move_uploaded_file($file['tmp_name'], $new_filename);
     return Path::toAsset($new_filename, $add_root_variable);
 }
Esempio n. 4
0
 /**
  * Checks if the page or any of its files are writable
  *
  * @return boolean
  */
 public function isWritable()
 {
     $folder = new Folder($this->root());
     if (!$folder->isWritable()) {
         return false;
     }
     foreach ($folder->files() as $f) {
         if (!$f->isWritable()) {
             return false;
         }
     }
     return true;
 }
Esempio n. 5
0
 public static function are_users_writable()
 {
     return Folder::isWritable('_config/users/');
 }
Esempio n. 6
0
 protected static function checkContent()
 {
     $folder = new Folder(kirby()->roots()->content());
     return $folder->isWritable(true);
 }
Esempio n. 7
0
 protected static function checkContent()
 {
     $folder = new Folder(c::get('root.content'));
     return $folder->isWritable(true);
 }