Jump to content

Permissions for Unlink Deleting Files in PHP and Security Concerns


dprichard

Recommended Posts

I am using unlink for the first time to delete files. I have permissions to write the files and am having no issues getting the files onto the server, but am getting permission denied when trying to delete them.

 

 

Warning: unlink(../galleries/uploads/Test/) [function.unlink]: Permission denied in photo-add.php on line 99

 

This is a Windows box with write permissions on the folders. I am trying to make sure I do this right and make sure I am not opening up any security holes. What permission do I need on this folder and what security concerns should I consider when deleting files.

 

Thank you for any and all advice.

 

I am trying to delete a file, but it doesn't seem to be pulling in my file name.

 

	if(file_exists("../galleries/uploads/".$row_galleryinfo['Name']."/".$row_photoinfo['FileName'])) {
	unlink("../galleries/uploads/".$row_galleryinfo['Name']."/".$row_photoinfo['FileName']);
}

lol Rhodesa

 

In IIS you have to give full control if you want to delete subfolders and files. The default user for IIS is IUSR_computername. Where computer name is the name of your computer.

 

So if you want to delete files in one particular folder then you can give modify rights to the account in that folder. If you want to delete files AND folders you have to give full control to the IUSR account.

 

so in the case above you can give full control to the uploads folder. also when you change the permissions click advanced and check off "Replace permission entries on all child...." This will reset all permissions on the files and folders below. Like a recursive chmod in linux.

 

Hope that makes sense.

 

Ray

gotchya...but yeah. seems to be not finding the filename, where is the code that sets $row_photoinfo['FileName'] ?

 

Also, you may want to use is_file() instead of file_exists() cus file_exists() will return true if it's a folder.

Yes, the PhotoId is coming from a post.  Then I query the database for the filename for the photoid.  I am doing this before the query though:

 

$PhotoId = '';
$PhotoId = mysql_real_escape_string($_POST['PhotoId']);

 

Then my query.  Should I take additional precautions beyond this?

 

Thanks you so much for your input.

Yes, the PhotoId is coming from a post.  Then I query the database for the filename for the photoid.  I am doing this before the query though:

 

$PhotoId = '';
$PhotoId = mysql_real_escape_string($_POST['PhotoId']);

 

Then my query.  Should I take additional precautions beyond this?

 

Thanks you so much for your input.

 

That should be good as long as you test to make sure a record is found before doing any unlinking.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.