Jump to content

[SOLVED] Multiple file upload problem


john010117

Recommended Posts

I've retrieved a multiple file upload code sample from php.net and extended/modified it to suit my needs (that uses arrays). For some reason, it uploads and moves the file from the temp directory to the folder I specified, but I get this error:

Warning: basename() expects parameter 1 to be string, array given in...

 

And here's the part of the code that I'm having trouble with.

 

<?php
$upload_dir = "images/";
$upload_file = $upload_dir . basename($_FILES['comicfile']['tmp_name']);
$filename = $_FILES['comicfile']['name'];
?>

(I just put the PHP tags in to help others be able to read the code clearly)

 

I've also tried pathinfo(), but to no avail. Can anybody help please?

Link to comment
Share on other sites

Sure thing.

 

<?php
$upload_dir = "images/";
$upload_file = $upload_dir . pathinfo($_FILES['comicfile']['tmp_name']);
$filename = $_FILES['comicfile']['name'];
$ok=1;

//This is our size condition
foreach ($_FILES['comicfile']['size'] as $filesize){
$comicfile_size = $filesize;
if ($comicfile_size > 100000000)
  {
  echo "<font color=\"#FF0000\">Failed</font>: Your file is too large.";
  $ok=0;
  }
}

//This is our limit file type condition
foreach ($_FILES['comicfile']['type'] as $filetype){
$comicfile_type = $filetype;
  if ($comicfile_type =="text/php")
  {
  echo "<font color=\"#FF0000\">Failed</font>: No PHP files.";
  $ok=0;
  }
}  

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "  Sorry your file was not uploaded";
}

//If everything is ok we try to upload it
else
{
foreach ($_FILES['comicfile']['error'] as $key => $error){
  if ($error == UPLOAD_ERR_OK) {
  $tmp_name = $_FILES['comicfile']['tmp_name'][$key];
  $name = $_FILES['comicfile']['name'][$key];
  move_uploaded_file($tmp_name, "images/$name");
  }
}

echo "<br />";
echo "<a href=\"index.php\">Comic Index</a><br />";
echo "<a href=\"http://rvb.allaroundhalo.org/index.php\">RvB Index</a><br />";
echo "<a href=\"http://www.allaroundhalo.org/index.php\">AAH Index</a>";

}
?>

Link to comment
Share on other sites

Well, you define the var $upload_file in the line where you use basename() or pathinfo(), but you never use that variable in this code!

 

Try either commenting out the line, or deleting it and see if that makes a difference to the function of your script

Link to comment
Share on other sites

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.