Jump to content


Photo

Moving multiple uploads? Sea of errors!


  • Please log in to reply
3 replies to this topic

#1 nineninefour

nineninefour
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 27 June 2006 - 06:31 AM

Hello!

Well, I've done my best. I've googled, ask.comed, read the documentation and searched the forums.

I'm trying to move uploaded files to an already created directory:

Here's the (abbreviated) form. I'm aware there is no doctype or anything. I'm just trying to get the php to work first:

<html>
<body>

<form name="upload" enctype="multipart/form-data" action="uploadtest.php" method="post">

Item Name: 
<p>
Upload Your Pictures!
<input  type="file" name="userfile[]" />
<input  type="file" name="userfile[]" />
<input  type="file" name="userfile[]" />
<input  type="file" name="userfile[]" />
<input  type="file" name="userfile[]" />
</p>
<br />
<input type="submit" value="Add New item!" />

</form> 



</body>
</html>


And here is the php:

<?php
$dbh=mysql_connect ("localhost", "XXXXXXXXX", "XXXXXXX") 
        or die ('I cannot connect to the database because: ' . mysql_error());
     mysql_select_db ("ninenine_xxxxxxxxx");

$num = rand(0, 99999);
$umask = umask(0);
$default = "default.html";
$dest = "items/$num/default.html";
$uploaddir = "items/$num/images/";
$uploadfile = $uploaddir . basename($_FILES['userfile']['name'][$key]);

mkdir("items/$num", 0777); //gets created no prob
mkdir("$uploaddir", 0777); //also works great
umask($umask);
copy($default, $dest); //copies my default file into the new directory, works great

foreach($_FILES['userfile']['name'] as $key => $value) 
    {
       move_uploaded_file($_FILES['userfile']['tmp_name'][$key], $uploadfile);  //THIS IS LINE 27
    }

?>

Here is the error i get:


Warning: move_uploaded_file(items/32142/images/): failed to open stream: Is a directory in /home/ninenine/public_html/vegasitems/uploadtest.php on line 27

Warning: move_uploaded_file(): Unable to move '/tmp/phppnPllB' to 'items/32142/images/' in /home/ninenine/public_html/vegasitems/uploadtest.php on line 27

Warning: move_uploaded_file(items/32142/images/): failed to open stream: Is a directory in /home/ninenine/public_html/vegasitems/uploadtest.php on line 27

Warning: move_uploaded_file(): Unable to move '/tmp/phpWjD0Ml' to 'items/32142/images/' in /home/ninenine/public_html/vegasitems/uploadtest.php on line 27


#2 nineninefour

nineninefour
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 28 June 2006 - 06:49 AM

Bump [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]


#3 adamwhiles

adamwhiles
  • Members
  • PipPipPip
  • Advanced Member
  • 54 posts

Posted 28 June 2006 - 07:07 AM

try changing this line:

move_uploaded_file($_FILES['userfile']['tmp_name'][$key], $uploadfile);

to this:

$file = $_FILES["userfile"]["tmp_name"][$key];
move_uploaded_file($file, "items/$num/images/$uploadfile");


#4 nineninefour

nineninefour
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 28 June 2006 - 09:50 AM

Awesome! Thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users