CincoPistolero Posted November 23, 2007 Share Posted November 23, 2007 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. Quote Link to comment Share on other sites More sharing options...
only one Posted November 23, 2007 Share Posted November 23, 2007 try something like: <?php if(file_exists($_FILES['name'])) { unlink('{$_FILES['name']}'); //now upload it. } else { //mysql query and whatever else you have there. } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.