Jump to content

invalid argument warning


bmbc

Recommended Posts

[code]<?php
// ini_set() does not work under safe mode
ini_set(upload_max_filesize, "50kb");
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, "upload/$name");
   }
}
?> [/code]

I don't know why there is a warning on the line foreach.
Any help appreciated.

Thanks
Link to comment
Share on other sites

Then it means that $_FILES["pictures"]["error"] is not an array.

You can only pass an associative array to the foreach.


[a href=\"http://us2.php.net/manual/en/features.file-upload.php\" target=\"_blank\"]http://us2.php.net/manual/en/features.file-upload.php[/a]

Link to comment
Share on other sites

Thanks again but sorry how do I do that?
pictures is in the htm - is that what you mean?
I checked the php on a site called www.meandeviation.com/tutorials/ learnphp/php-syntax-check/
and it didn't come up with any syntax errors.

Ok I just went to that link you gave me and there is
the script I'm using which comes up with the exact
same warning. Why are they giving that example if it
doesn't work?
Link to comment
Share on other sites

[code]<div id="upload">
<form action="" method="post" enctype="multipart/form-data">

<p>Pictures:
<li><input type="file" name="pictures[]" /></li>
<li><input type="file" name="pictures[]" /></li>
<li><input type="file" name="pictures[]" /></li>
<li><input type="file" name="pictures[]" /></li>
<li><input type="file" name="pictures[]" /></li>
<li><input type="submit" value="Send" /></li>
</p>
</form>
</div> [/code]

What is wrong with this?
Link to comment
Share on other sites

[!--quoteo(post=365217:date=Apr 15 2006, 08:14 PM:name=bmbc)--][div class=\'quotetop\']QUOTE(bmbc @ Apr 15 2006, 08:14 PM) [snapback]365217[/snapback][/div][div class=\'quotemain\'][!--quotec--]
What is wrong with this?
[/quote]
Action is missing it's value.
Link to comment
Share on other sites

I'm really sorry but I just don't follow.
action is missing it's value- which action(?) and
why does the php tutorial use the exact same
code as the working example?

OOOOOPS SORRY!!!!! I just got it - how embarrassing is that!
Ok so the action should be upload right or should it be post?
Anyway thanks :)
Link to comment
Share on other sites

Action contains the name of your PHP script that's going to handle the upload processing (like the name of the script that contains the code in your original post here). Example:

<form action="myuploadscriptname.php" method="post" enctype="multipart/form-data">

So, when the form is submitted it will send all the $_FILES data filled-in to your upload.php script.
Link to comment
Share on other sites

Yes, I just worked that out :)
I separated the php page from the htm one and set the action to the name of the php
and there is no more warning.
Problem now is the file size restriction doesn't work , it just ignores it and
let's me upload any size I want.
Also I need to create an error and successful upload page script.
Plus I was hoping to be able to send text with the images to the same uploads folder
but I don't know how that would work let alone so the images and text would be
associated.
Link to comment
Share on other sites

For PHP <= 4.2.3 you can set it using ini_set(). But if you have a higher version PHP then upload_max_filesize can only be set in the php.ini file or .htaccess file.

[a href=\"http://us2.php.net/manual/en/ini.core.php#AEN246248\" target=\"_blank\"]http://us2.php.net/manual/en/ini.core.php#AEN246248[/a]

Read some more tutorials.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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