delFile() public method

Delete a file.
public delFile ( string $file ) : boolean
$file string file to be deleted
return boolean true if deleted, false otherwise.
 /**
  * Delete the relative file, and any thumbnails.
  * @param string $relative the relative file.
  * @return boolean true if deleted, false otherwise.
  */
 function _delFile($relative)
 {
     $fullpath = Files::makeFile($this->getImagesDir(), $relative);
     //check that the file is an image
     if ($this->config['validate_images'] == true) {
         if (!is_array($this->getImageInfo($fullpath))) {
             return false;
         }
         //hmmm not an Image!!???
     }
     $thumbnail = $this->getThumbName($fullpath);
     if (Files::delFile($fullpath)) {
         return Files::delFile($thumbnail);
     } else {
         return false;
     }
 }
 /**
  * Delete any tmp image files.
  * @param string $path the full path 
  * where the clean should take place.
  */
 function cleanUp($path, $file)
 {
     $path = Files::fixPath($path);
     if (!is_dir($path)) {
         return false;
     }
     $d = @dir($path);
     $tmp = $this->manager->getTmpPrefix();
     $tmpLen = strlen($tmp);
     $prefix = $tmp . $this->_uid;
     $len = strlen($prefix);
     while (false !== ($entry = $d->read())) {
         //echo $entry."<br>";
         if (is_file($path . $entry) && $this->manager->isTmpFile($entry)) {
             if (substr($entry, 0, $len) == $prefix && $entry != $file) {
                 Files::delFile($path . $entry);
             } else {
                 if (substr($entry, 0, $tmpLen) == $tmp && $entry != $file) {
                     if (filemtime($path . $entry) + $this->lapse_time < time()) {
                         Files::delFile($path . $entry);
                     }
                 }
             }
         }
     }
     $d->close();
 }
Beispiel #3
0
 /**
  * Delete folder(s), can delete recursively.
  * @param string $folder the folder to be deleted.
  * @param boolean $recursive if true, all files and sub-directories
  * are delete. If false, tries to delete the folder, can throw
  * error if the directory is not empty.
  * @return boolean true if deleted.
  */
 function delFolder($folder, $recursive = false)
 {
     $deleted = true;
     if ($recursive) {
         $d = dir($folder);
         while (false !== ($entry = $d->read())) {
             if ($entry != '.' && $entry != '..') {
                 $obj = Files::fixPath($folder) . $entry;
                 //var_dump($obj);
                 if (is_file($obj)) {
                     $deleted &= Files::delFile($obj);
                 } else {
                     if (is_dir($obj)) {
                         $deleted &= Files::delFolder($obj, $recursive);
                     }
                 }
             }
         }
         $d->close();
     }
     //$folder= $folder.'/thumbs';
     //var_dump($folder);
     if (is_dir($folder)) {
         $deleted &= rmdir($folder);
     } else {
         $deleted &= false;
     }
     return $deleted;
 }
 /**
  * Renames files if certain GET variables are set
  * @return bool
  */
 function processRenames()
 {
     if (!empty($_GET['rename']) && !empty($_GET['renameTo'])) {
         // new file name (without path and extension)
         $newName = Files::escape(rawurldecode($_GET['renameTo']));
         $newName = str_replace('.', '', $newName);
         // path to file (from base images directory)
         $oldName = rawurldecode($_GET['rename']);
         // strip parent dir ("..") to avoid escaping from base directiory
         $oldName = preg_replace('#\\.\\.#', '', $oldName);
         if (is_dir($oldPath = Files::makeFile($this->getImagesDir(), $_GET['dir'] . $oldName))) {
             $newPath = Files::makeFile($this->getImagesDir(), $_GET['dir'] . $newName);
             return Files::rename($oldPath, $newPath);
         } else {
             // path to old file
             $oldPath = Files::makeFile($this->getImagesDir(), $oldName);
             $ret = Files::renameFile($oldPath, $newName);
             if ($ret === true) {
                 // delete old thumbnail
                 Files::delFile($this->getThumbname($oldPath));
             }
         }
         return $ret;
     }
     return null;
 }
 /**
  * Delete the relative file, and any thumbnails.
  * @param string $relative the relative file.
  * @return boolean true if deleted, false otherwise.
  */
 function _delFile($relative)
 {
     $fullpath = Files::makeFile($this->getBaseDir(), $relative);
     //check that the file is an image
     if ($this->config['validate_images']) {
         if (!is_array($this->getImageInfo($fullpath))) {
             return false;
         }
         //hmmm not an Image!!???
     }
     $thumbnail = $this->getThumbName($fullpath);
     if (Files::delFile($fullpath)) {
         //deleting from the DB
         global $_course;
         if (isset($_course) && !empty($_course) && isset($_course['code'])) {
             $document_path = substr($fullpath, strpos($fullpath, '/document/') + 9, strlen($fullpath));
             //   /shared_folder/4/name
             DocumentManager::delete_document($_course, $document_path, $fullpath);
         }
         return Files::delFile($thumbnail);
     } else {
         return false;
     }
 }
Beispiel #6
0
<?php

require_once '../classes/Autoload.php';
$session = new Session();
if ($session->isLoggeg()) {
    $cancion = new Cancion(Request::get('c'));
    var_dump($cancion);
    if ($cancion != null) {
        $rutaCan = "../canciones/" . $cancion->getNombre();
        $rutaImg = "../caratulas/" . $cancion->getImagen();
        Files::delFile($rutaCan);
        if (is_file($rutaImg) && Files::getFileName($rutaCan) === Files::getFileName($rutaImg)) {
            Files::delFile($rutaImg);
        }
    }
}
Utils::redirect();