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
https://forums.phpfreaks.com/topic/48545-solved-multiple-file-upload-problem/
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>";

}
?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.