Jump to content

Moving multiple uploads? Sea of errors!


nineninefour

Recommended Posts

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:

[code]
<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>
[/code]


And here is the php:

[code]
<?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
    }

?>
[/code]

Here is the error i get:

[code]

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
[/code]
Link to comment
https://forums.phpfreaks.com/topic/12999-moving-multiple-uploads-sea-of-errors/
Share on other sites

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.