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
https://forums.phpfreaks.com/topic/7520-invalid-argument-warning/
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?
[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?
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 :)
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.
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.
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.

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.