Jump to content

Image upload unlink issue


CincoPistolero

Recommended Posts

I have a site that uploads and formats an image to my website. Currently, when I add new, it uploads the image and names it by the ID associated with the subject (ie. 8.gif). The problem occurs when I go to modify the data. The current code I have unlinks the original URL then adds a new image with no name and just the .gif extension. It is supposed to remove the old image, replace the new and reset the link. Can someone look at my code and see if they see anything wrong? Code below:

 

The 'name=' from sending page is 'photo_img', the database column name is 'photoUrl'

 

$personalPhoto=$row['photoUrl'];
if (!ereg("^[ \t\r\n]*$",$_FILES['photo_img']['name']) && is_uploaded_file($_FILES['photo_img']['tmp_name']) && !empty($_FILES['photo_img']['size'])) {
if (!ereg('default\.jpg$',$row['photoUrl']) && !ereg("^[ \t\r\n]*$",$row['photoUrl'])) {
	@unlink('/location/of/where/imageIs/stored'.$row['photoUrl']);
}
require_once('createimage.php');
createImage($_FILES['photo_img']['tmp_name'], '/location/of/where/imageIs/stored/images/aboutUsImages/'.$row['aboutUsID'].'.gif');
if (!(mysql_query("UPDATE aboutUs SET photoUrl='images/aboutUsImages/{$row['aboutUsID']}.gif' WHERE aboutUsID='{$row['aboutUsID']}'"))) {
	@unlink('/location/of/where/imageIs/stored/images/aboutUsImages/'.$row['aboutUsID'].'.gif');
} else $personalPhoto='images/aboutUsImages/'.$row['aboutUsID'].'.gif';
}

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/78588-image-upload-unlink-issue/
Share on other sites

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.