dennismonsewicz Posted October 21, 2008 Share Posted October 21, 2008 I am doing a multiple file upload and I was wondering how would the array breakdown for the $_FILES var as far as using the ['tmp_name'] goes? This is the code I am working with: foreach($_FILES['uploadedfile']['name'] as $key) { if(!empty($key)) { if(move_uploaded_file("uploads/" . $_FILES['uploadedfile']['tmp_name'], $target_path)) { $att_qry = mysql_query("INSERT INTO uploads (upload_name, upload_path, project_name, project_id) VALUES ('$key', '$target_path', '$project_name', '" . $idresults->id . "')")or die(mysql_error()); } } } How would does the ['tmp_name'] and the $key values match up when moving the file? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 21, 2008 Share Posted October 21, 2008 if i remember right, it should be like so: foreach($_FILES['uploadedfile']['name'] as $n=>$name) { if(move_uploaded_file("uploads/" . $_FILES['uploadedfile']['tmp_name'][$n], $target_path)) { $att_qry = mysql_query("INSERT INTO uploads (upload_name, upload_path, project_name, project_id) VALUES ('$name', '$target_path', '$project_name', '" . $idresults->id . "')")or die(mysql_error()); } } ...but that will keep overwritting $targetpath...i assume you want a different $targetpath for each file? Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted October 21, 2008 Author Share Posted October 21, 2008 this is what i have: foreach($_FILES['uploadedfile']['name'] as $key) { if(!empty($key)) { $target_path = "uploads/" . $key . "<br />"; echo $target_path; if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$key], $target_path)) { $att_qry = mysql_query("INSERT INTO uploads (upload_name, upload_path, project_name, project_id) VALUES ('$key', '$target_path', '$project_name', '" . $idresults->id . "')")or die(mysql_error()); } else { echo '<p>Don\'t work boss!</p>'; } } } And no each file needs to go in the same uploads folder Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 21, 2008 Share Posted October 21, 2008 try this: foreach($_FILES['uploadedfile']['name'] as $n => $name) { if(!empty($name)) { $target_path = "uploads/" . $name; echo $target_path . "<br />"; if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$n], $target_path)) { mysql_query("INSERT INTO uploads (upload_name, upload_path, project_name, project_id) VALUES ('$name', '$target_path', '$project_name', '" . $idresults->id . "')") or die(mysql_error()); } else { echo '<p>Didn\'t work boss!</p>'; } } } Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted October 21, 2008 Author Share Posted October 21, 2008 Sweet it worked! Thanks a ton man! 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.