Jump to content

simple multiple file upload script issues


tpl41803

Recommended Posts

Hey all

 

I have an issue with a really bare file uploading script which is supposed to upload up to 40 files at the same time, rename them, and save them to a predetermined directory.

 

 

My code on a page called PHOTOS looks like this (shortened because it's the same thing repeated for each input):

<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="destination" value="$row['folder']" />
1. <input name="ufile[]" type="file" id="ufile[]" /><br />
2. <input name="ufile[]" type="file" id="ufile[]" /><br />
3. <input name="ufile[]" type="file" id="ufile[]" /><br />
4. <input name="ufile[]" type="file" id="ufile[]" /><br />
etc...

 

and my php action, "upload.php" looks like this:

 

$destination = $_POST['destination'];

$path1= "../sales/inventory/$destination/". "1.jpg";
$path2= "../sales/inventory/$destination/". "2.jpg";
$path3= "../sales/inventory/$destination/". "3.jpg";
$path4= "../sales/inventory/$destination/". "4.jpg";
etc....

if (!empty($_FILES['ufile']['tmp_name'][0])) { copy($_FILES['ufile']['tmp_name'][0], $path1); }
if (!empty($_FILES['ufile']['tmp_name'][1])) { copy($_FILES['ufile']['tmp_name'][1], $path2); }
if (!empty($_FILES['ufile']['tmp_name'][2])) { copy($_FILES['ufile']['tmp_name'][2], $path3); }
if (!empty($_FILES['ufile']['tmp_name'][3])) { copy($_FILES['ufile']['tmp_name'][3], $path4); }
etc...

 

I'm sure there are prettier ways of doing this, but it works fine until I upload a 21st files.

 

The script for some reason will only save the first 20 files to the destination directory.

 

I have changed the max file upload size to reflect the amount of bytes I am passing through this script (which is rarely more than 4.5mb).

 

Any ideas why this might be happening?

 

Thanks a lot, always appreciate the help I get when i come here!

I have been playing with the script a little and adding some checks into the code and this new version produces the exact same problem, example:

 

if (!empty($_FILES['ufile']['tmp_name'][0])) {
       if (!copy($_FILES['ufile']['tmp_name'][0], $path0)) {
            echo "failed to save '.$path1.'";
        }
       echo "'.$path0.' was saved <br /><br />";
     } else {
       echo "'.$path0.' was empty <br /><br />";
     }

 

Now, when I upload the first 20 files, i receive "XXXX was saved" and 21-40 returns "XXXX was empty"

 

DOES php only allow the userfile array only count to 20?

 

I'm not sure if this is really the issue, because if i only upload the 21st file, for example, the script still returns "XXXX was empty" for number 21.

 

not sure :-/

When I try this simple script:

<?php
<?php
if (isset($_POST['submit'])) {
	echo '<pre>' . print_r($_FILES['ufile'],true) . '</pre>';
}
?>
<html>
<head>
	<title>Upload many files</title>
</head>
<body>
	<form enctype="multipart/form-data" action="" method="POST">
		<ol>
			<?php
				for($i=0;$i<40;++$i) {
					echo '<li><input name="ufile[]" type="file" id="ufile[]" /><br />' . "\n";
				}
			?>
		</ol>
		<input type="submit" value="Upload" name="submit">
	</form>
</body>
</html>

 

I get the following warning:

Warning: Maximum number of allowable file uploads has been exceeded in Unknown on line 0

 

And it only populates 20 entries in the $_FILES array.

 

Ken

seems this is the issue, i have broken my script into 2 separate pages, each uploads 20 files at a time, this is not EXACTLY what I was looking for, but it will do until I can find away to override what seems to be a 20 file maximum

 

I've looked through the php.ini settings to see if there is a way to change it but it seems like there isn;t

 

thanks for all your help :-D

You can increase the count by altering max_file_uploads

 

cf http://www.php.net/manual/en/ini.core.php#ini.max-file-uploads

 

Chances are you also may want to increase upload_max_filesize with 8M you would have 200KB for each file.

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.