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>"; ?> 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.