Gdn_Upload::delete PHP Method

delete() public method

Delete an uploaded file.
public delete ( string $Name ) : boolean
$Name string The name of the upload as saved in the database.
return boolean
    public function delete($Name)
    {
        $Parsed = $this->parse($Name);
        // Throw an event so that plugins that have stored the file somewhere else can delete it.
        $this->EventArguments['Parsed'] =& $Parsed;
        $Handled = false;
        $this->EventArguments['Handled'] =& $Handled;
        $this->fireAs('Gdn_Upload')->fireEvent('Delete');
        if (!$Handled) {
            $Path = PATH_UPLOADS . '/' . ltrim($Name, '/');
            if ($Path === realpath($Path) && file_exists($Path)) {
                return safeUnlink($Path);
            }
        }
        return true;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Remove the photo from a user.
  *
  * @param int $UserID
  */
 public function removePicture($UserID)
 {
     // Grab the current photo.
     $User = $this->getID($UserID, DATASET_TYPE_ARRAY);
     $Photo = $User['Photo'];
     // Only attempt to delete a physical file, not a URL.
     if (!isUrl($Photo)) {
         $ProfilePhoto = changeBasename($Photo, 'p%s');
         $Upload = new Gdn_Upload();
         $Upload->delete($ProfilePhoto);
     }
     // Wipe the Photo field.
     $this->setField($UserID, 'Photo', null);
 }
All Usage Examples Of Gdn_Upload::delete