bmbc Posted April 16, 2006 Share Posted April 16, 2006 [code]<?php// ini_set() does not work under safe modeini_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 Quote Link to comment https://forums.phpfreaks.com/topic/7520-invalid-argument-warning/ Share on other sites More sharing options...
toplay Posted April 16, 2006 Share Posted April 16, 2006 It's the line before. You forgot the quotes on the ini_set. Example:ini_set('upload_max_filesize', '50kb'); Quote Link to comment https://forums.phpfreaks.com/topic/7520-invalid-argument-warning/#findComment-27377 Share on other sites More sharing options...
bmbc Posted April 16, 2006 Author Share Posted April 16, 2006 Thanks but I made the change and I'm still getting the same warning. Quote Link to comment https://forums.phpfreaks.com/topic/7520-invalid-argument-warning/#findComment-27380 Share on other sites More sharing options...
toplay Posted April 16, 2006 Share Posted April 16, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/7520-invalid-argument-warning/#findComment-27381 Share on other sites More sharing options...
neylitalo Posted April 16, 2006 Share Posted April 16, 2006 an "Invalid argument in foreach" error is thrown when you give foreach() something that isn't an array. So you need to make sure that $_FILES['pictures']['errors'] is indeed an array. Quote Link to comment https://forums.phpfreaks.com/topic/7520-invalid-argument-warning/#findComment-27382 Share on other sites More sharing options...
bmbc Posted April 16, 2006 Author Share Posted April 16, 2006 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 isthe script I'm using which comes up with the exact same warning. Why are they giving that example if itdoesn't work? Quote Link to comment https://forums.phpfreaks.com/topic/7520-invalid-argument-warning/#findComment-27383 Share on other sites More sharing options...
toplay Posted April 16, 2006 Share Posted April 16, 2006 HTML form must be an array (use of []). See code example at:[a href=\"http://us2.php.net/manual/en/features.file-upload.php#AEN7125\" target=\"_blank\"]http://us2.php.net/manual/en/features.file...oad.php#AEN7125[/a] Quote Link to comment https://forums.phpfreaks.com/topic/7520-invalid-argument-warning/#findComment-27384 Share on other sites More sharing options...
bmbc Posted April 16, 2006 Author Share Posted April 16, 2006 [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? Quote Link to comment https://forums.phpfreaks.com/topic/7520-invalid-argument-warning/#findComment-27385 Share on other sites More sharing options...
toplay Posted April 16, 2006 Share Posted April 16, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/7520-invalid-argument-warning/#findComment-27386 Share on other sites More sharing options...
bmbc Posted April 16, 2006 Author Share Posted April 16, 2006 I'm really sorry but I just don't follow. action is missing it's value- which action(?) andwhy 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 :) Quote Link to comment https://forums.phpfreaks.com/topic/7520-invalid-argument-warning/#findComment-27387 Share on other sites More sharing options...
toplay Posted April 16, 2006 Share Posted April 16, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/7520-invalid-argument-warning/#findComment-27389 Share on other sites More sharing options...
bmbc Posted April 16, 2006 Author Share Posted April 16, 2006 Yes, I just worked that out :) I separated the php page from the htm one and set the action to the name of the phpand there is no more warning.Problem now is the file size restriction doesn't work , it just ignores it andlet'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 folderbut I don't know how that would work let alone so the images and text would beassociated. Quote Link to comment https://forums.phpfreaks.com/topic/7520-invalid-argument-warning/#findComment-27390 Share on other sites More sharing options...
toplay Posted April 16, 2006 Share Posted April 16, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/7520-invalid-argument-warning/#findComment-27391 Share on other sites More sharing options...
bmbc Posted April 16, 2006 Author Share Posted April 16, 2006 Thanks so much for your help today toplay.I will save any other questions I have for another time when I've read more of the tutorials and forum entries. Quote Link to comment https://forums.phpfreaks.com/topic/7520-invalid-argument-warning/#findComment-27393 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.