Page 1 of 1

How to delete uploaded picture

Posted: Sun Sep 11, 2005 2:06 pm
by Cateyes
Hi I have a program where I upload a picture for a profile here is the code it works great. What I need to know is it possible when a profile is deleted to be able to delete the picture at the same time I use a DB that has the profile as well as the pic location I know how to delete the profile but can't seem to find anything for deleting the picture.

Code: Select all

<?php
set_time_limit(0);
// Set up multiple uploads if you want
$numoffile = 1;
// Fix path of your file to be uploaded
$file_dir = "../images/vehicles/"; // folder name for uploaded file
if ($_POST) {
for ($i=0;$i<$numoffile;$i++) {
if (trim($_FILES['myfiles']['name'][$i])!="") {
$newfile = $file_dir.$_FILES['myfiles']['name'][$i];
move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile);
$newfile1 = str_replace("..", "", $newfile);
}
}
}
 
if (isset($i)&&$i>0){
	header("Location: ins_stock.php?fileID=".$newfile1); 
    exit;
}
print "<form method='post' enctype='multipart/form-data'>";
for($i=0;$i<$numoffile;$i++) {
print "<input type='file' name='myfiles[]' size='30'><br>";
}
print "<br><input type='submit' name='action' value='Upload File'>";
print "</form>";
?>

Posted: Sun Sep 11, 2005 2:15 pm
by feyd

Posted: Sun Sep 11, 2005 2:18 pm
by Cateyes
Thanks Feyd you seem to be a walking encylopedia I have 4 PHP books and not one discussed how to do it.

Posted: Sun Sep 11, 2005 7:53 pm
by timvw
That's odd, because even http://www.php.net/delete guides you to the right place :)

Posted: Sun Sep 11, 2005 7:56 pm
by Cateyes
Yeah I found that out afterwards I tried remove and got nothing I find when you step away and come back you usually type in an easier search and like magic the answer is there. :wink: