Jump to content

Recommended Posts

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?

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?

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

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>';
    }
  }
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.