john010117 Posted April 25, 2007 Share Posted April 25, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/48545-solved-multiple-file-upload-problem/ Share on other sites More sharing options...
sanfly Posted April 25, 2007 Share Posted April 25, 2007 Where in the code do you use basename()? Can you post that please Quote Link to comment https://forums.phpfreaks.com/topic/48545-solved-multiple-file-upload-problem/#findComment-237661 Share on other sites More sharing options...
john010117 Posted April 25, 2007 Author Share Posted April 25, 2007 Whoops! I forgot to change pathinfo() to basename() in the code that I posted above. That's the part of the code that I'm having trouble with. Quote Link to comment https://forums.phpfreaks.com/topic/48545-solved-multiple-file-upload-problem/#findComment-237664 Share on other sites More sharing options...
sanfly Posted April 25, 2007 Share Posted April 25, 2007 Okay, i dont get what this line $upload_file = $upload_dir . basename($_FILES['comicfile']['tmp_name']); is supposed to achieve. Can you post the rest of your code again Quote Link to comment https://forums.phpfreaks.com/topic/48545-solved-multiple-file-upload-problem/#findComment-237675 Share on other sites More sharing options...
john010117 Posted April 25, 2007 Author Share Posted April 25, 2007 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/48545-solved-multiple-file-upload-problem/#findComment-237691 Share on other sites More sharing options...
sanfly Posted April 25, 2007 Share Posted April 25, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/48545-solved-multiple-file-upload-problem/#findComment-237696 Share on other sites More sharing options...
john010117 Posted April 25, 2007 Author Share Posted April 25, 2007 I have no idea why I put that in the code. Heh, maybe I should slow down on coding stuff. Ok, thank you. It worked. Quote Link to comment https://forums.phpfreaks.com/topic/48545-solved-multiple-file-upload-problem/#findComment-237704 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.