wpmills Posted March 6, 2006 Share Posted March 6, 2006 I use the following code to upload photos for a talent agency site.What I want to know is how to alter it to allow me to delete the old file if a new one is added. At the moment all that happens is the new path is written to the database and the new image copied over. The old image remains.Any suggestions?<?php$talent_id = $_GET['talent_id']; $numoffile = 5; $file_dir = "../images/uploads/"; if ($_POST) { for ($i=0;$i<$numoffile;$i++) { if (trim($_FILES['myfiles']['name'][$i])!="") { $newfile = $file_dir.md5(rand() * time()).' - '.$_FILES['myfiles']['name'][$i]; move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile); $j++; include './includes/dbconnect.php'; $query = "UPDATE talent_info SET image_path$i=coalesce('$newfile') WHERE talent_id = '$talent_id'"; $result = mysql_query($query) or die(mysql_error()); } } } if (isset($j)&&$j>0) print "Your file(s) has been uploaded. Return to<a href='./add_talent.php'>Add Talent</a>.<br>"; print "<form method='post' enctype='multipart/form-data'>"; for($i=0;$i<$numoffile;$i++) { print "Image $i<input type='file' name='myfiles[]' size='30'><br>"; } print "<input type='submit' name='action' value='Upload'>"; print "</form>"; ?> Link to comment https://forums.phpfreaks.com/topic/4205-delete-file-referenced-by-path/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.