How to delete uploaded picture

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Cateyes
Forum Commoner
Posts: 63
Joined: Mon Jun 14, 2004 5:06 pm

How to delete uploaded picture

Post 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>";
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Cateyes
Forum Commoner
Posts: 63
Joined: Mon Jun 14, 2004 5:06 pm

Post by Cateyes »

Thanks Feyd you seem to be a walking encylopedia I have 4 PHP books and not one discussed how to do it.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

That's odd, because even http://www.php.net/delete guides you to the right place :)
Cateyes
Forum Commoner
Posts: 63
Joined: Mon Jun 14, 2004 5:06 pm

Post 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:
Post Reply