Jump to content

move_upload_file problem


superprg

Recommended Posts

Can someone please tell me why this wont work?

[a href=\"http://facebuddies.com/php_upload/move_upload/1.php\" target=\"_blank\"]http://facebuddies.com/php_upload/move_upload/1.php[/a]

Here is the code
[code]

<form action="" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="submit" value="Send" />
</p>
</form>

<?php
if(isset($_FILES['pictures']['error'])){
   foreach ($_FILES["pictures"]["error"] as $key => $error) {
      if ($error == UPLOAD_ERR_OK) {
         $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
         $name = $_FILES["pictures"]["name"][$key];
         move_uploaded_file($tmp_name, "data/$name");
      }
   }
}
?>  

[/code]


The strange thing is same code works on my local machine so I am sure this must be some configuration problem
San
Link to comment
https://forums.phpfreaks.com/topic/11180-move_upload_file-problem/
Share on other sites

what is it not doing, how large is the file, If it works on your local machine but not on your live server, you may need to talk to your host. Most shared hosts to not allow larger than 2MB uploads on there systems to prevent lag.

So it might not be a code issue.

Just a thought
[!--quoteo(post=380036:date=Jun 4 2006, 09:33 PM:name=homchz)--][div class=\'quotetop\']QUOTE(homchz @ Jun 4 2006, 09:33 PM) [snapback]380036[/snapback][/div][div class=\'quotemain\'][!--quotec--]
what is it not doing, how large is the file, If it works on your local machine but not on your live server, you may need to talk to your host. Most shared hosts to not allow larger than 2MB uploads on there systems to prevent lag.

So it might not be a code issue.

Just a thought
[/quote]

You got to use the correct form format heres an example ok.

[code]

<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="__URL__" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>
[/code]


Just set the file size ok.
[code]

<form enctype="multipart/form-data" action="" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input name="pictures[]" type="file" />
<input name="pictures[]" type="file" />
<input name="pictures[]" type="file" />
<input type="submit" value="Send File" />
</form>


<?php
if(isset($_FILES['pictures']['error'])){
   foreach ($_FILES["pictures"]["error"] as $key => $error) {
      if ($error == UPLOAD_ERR_OK) {
         $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
         $name = $_FILES["pictures"]["name"]["key"];
         move_uploaded_file($tmp_name, "data/$name");
      }
   }
}
?>

[/code]

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.