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? Link to comment https://forums.phpfreaks.com/topic/129394-solved-multiple-file-upload-move_uploaded_file-help/ 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? Link to comment https://forums.phpfreaks.com/topic/129394-solved-multiple-file-upload-move_uploaded_file-help/#findComment-670829 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 Link to comment https://forums.phpfreaks.com/topic/129394-solved-multiple-file-upload-move_uploaded_file-help/#findComment-670848 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>'; } } } Link to comment https://forums.phpfreaks.com/topic/129394-solved-multiple-file-upload-move_uploaded_file-help/#findComment-670852 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! Link to comment https://forums.phpfreaks.com/topic/129394-solved-multiple-file-upload-move_uploaded_file-help/#findComment-670859 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.