hi all, I was wondering what the easest way to enable a user to remove a file from the server would be? and where I may find an example to get me started?
Thanks
deleteFileFromServer();
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
function deleteFile($filepath) {
return (file_exists($filepath) && unlink($filepath));
}example usage
http://domain.com/delete.php?filepath=somefile.jpg
Code: Select all
if (!empty($_GET['filepath']) && deleteFile($_GET['filepath'])) {
echo 'file succesfuly deleted';
}using what you gave me I threw this togeather, do you think it will work to prevent people from removing files out side of the fileRoot dir?
Code: Select all
function deleteFileFromServer($filepath) {
if ($filepath){
// check that the file is within public root folder and not a system file
if(stristr($filepath, $this->fileRoot) === FALSE) {
echo "You do not have permission to remove that file from the server!";
return false;
}elseif (stristr($filepath, $this->fileRoot) === TRUE) {
return (file_exists($filepath) && unlink($filepath));
}else{
echo "Invalid File, Please select another file.";
}
}
}