[SOLVED] Cant upload more then 6 files?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Granda
Forum Newbie
Posts: 7
Joined: Thu Mar 03, 2005 5:05 pm

[SOLVED] Cant upload more then 6 files?

Post by Granda »

Hello all,

I need help, here is the code i use to upload files :

Code: Select all

// SLIKE
$result_final = "";
	$counter = 0;

	// List of our known photo types
	$known_photo_types = array( 
						'image/pjpeg' => 'jpg',
						'image/jpeg' => 'jpg',
						'image/bmp' => 'bmp',
						'image/x-png' => 'png'
					);
	
	// GD Function List
	$gd_function_suffix = array( 
						'image/pjpeg' => 'JPEG',
						'image/jpeg' => 'JPEG',
						'image/bmp' => 'WBMP',
						'image/x-png' => 'PNG'
					);
	
	// Fetch the photo array
	$photos_uploaded = $_FILESї'photo_filename'];
	$a = 0;
	
	// UPLOAD SLIKA !!!!
// initialization

	
	

	while( $counter <= count($photos_uploaded) )
	{
		if($photos_uploadedї'size']ї$counter] > 0)
		{
			if(!array_key_exists($photos_uploadedї'type']ї$counter], $known_photo_types))
			{
				$result_final .= "File ".($counter+1)." is not a photo<br />";
			}
			else
			{
				mysql_query( "INSERT INTO susreti_slike (`photo_filename`,`ID`) VALUES('0','$zadnji_id')" );
				$new_id = mysql_insert_id();
				$filetype = $photos_uploadedї'type']ї$counter];
				$extention = $known_photo_typesї$filetype];
				$filename = $new_id.".".$extention;

				mysql_query( "UPDATE susreti_slike SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );

				// Store the orignal file
				copy($photos_uploadedї'tmp_name']ї$counter], $images_dir2."/".$filename);

				// Let's get the Thumbnail size
				$size = GetImageSize( $images_dir2."/".$filename );
				if($sizeї0] > $sizeї1])
				{
					$thumbnail_width = 150;
					$thumbnail_height = (int)(150 * $sizeї1] / $sizeї0]);
				}
				else
				{
					$thumbnail_width = (int)(150 * $sizeї0] / $sizeї1]);
					$thumbnail_height = 150;
				}
			
				// Build Thumbnail with GD 2.x.x, you can use the other described methods too
				$function_suffix = $gd_function_suffixї$filetype]; 
				$function_to_read = 'ImageCreateFrom' . $function_suffix; 
				$function_to_write = 'Image' . $function_suffix; 

				// Read the source file 
				$source_handle = $function_to_read($images_dir2 . '/' . $filename); 
        
				if ($source_handle) { 
				 // Let's create a blank image for the thumbnail 
				 $destination_handle = 
 				  ImageCreateTrueColor($thumbnail_width, $thumbnail_height); 

				 // Now we resize it 
				 ImageCopyResampled($destination_handle, $source_handle,0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $sizeї0], $sizeї1]); 
				} 

				// Let's save the thumbnail 
				$function_to_write($destination_handle, $images_dir2 . '/tb_' . $filename);


				ImageDestroy($destination_handle );
				//

				$result_final .= "<img src='".$images_dir2. "/tb_".$filename."' /> File ".($counter+1)." Added<br />";
			}
		}
	$counter++;
	}


// END
I cant upload more then 6 files on my server. In my code i newer sad there was a 6 file limit...

I cant figure out the problem. If anyone can help i would apriciate it alot.

thx.


feyd | please use

Code: Select all

tags while the

Code: Select all

tags are offline![/color]
Last edited by Granda on Sat Mar 05, 2005 10:29 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it all comes down to your max_upload_size setting.. pretty much.. http://us3.php.net/manual/en/features.file-upload.php
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

The max_post_size setting in the ini also affects file upload limits since the upload is technically a POST operation.
Granda
Forum Newbie
Posts: 7
Joined: Thu Mar 03, 2005 5:05 pm

Post by Granda »

i dont understand. MAX_UPLOAD_SIZE in Kb? Becuase it doesent metter if i select 500Kb files or 5 Kb files, it always uploads 6.

When i echo my variable where i store the array it always returns 6. You can see my code. I realy dont understand the prob. If anyone can help it would be apriciated.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post your submitting code.. If you output 6 upload fields, you will get 6 uploads, even if 2 are used.
Granda
Forum Newbie
Posts: 7
Joined: Thu Mar 03, 2005 5:05 pm

Post by Granda »

Here is the whole file. I still didnt figure out what heppend. I asked my hosting provider to radise the limit, they sad i can now upload max 10MB, but that didnt change the 6 file limit...

Code: Select all

<?php
if (!isset($_POST&#1111;'Save'])):
?>
<form "<?=$_SERVER&#1111;'PHP_SELF']?>" method="post" enctype="multipart/form-data">
  <font size="1" face="Verdana, Arial, Helvetica, sans-serif">Datum odr&#158;avanja: 
  </font> 
  <input name="datum" type="text" id="datum">
  <br>
  <br>
  <font size="1" face="Verdana, Arial, Helvetica, sans-serif">Ime eventa : </font> 
  <input name="naslov" type="text" id="naslov">
  <br>
  <br>
  <font size="1" face="Verdana, Arial, Helvetica, sans-serif">Mjesto odr&#158;avanja :</font> 
  <input name="mjesto" type="text" id="mjesto"><br>
  <br>
  <font size="1" face="Verdana, Arial, Helvetica, sans-serif">text : </font><br>
  <textarea name="novost" cols="100" rows="20" wrap="soft" id="novost"></textarea>
  <br>
  <br>
  Slika 1 : 
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  Slika 2 : 
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  Slika 3 : 
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  Slika 4 : 
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  Slika 5 : 
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  Slika 6 : 
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  Slika 7 : 
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  Slika 8 : 
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <input name='photo_filename&#1111;]' type='file' size="80" /><br>
  <br>
  <br>
  <br>
  <input name="Save" type="submit" id="Save" value="save">
</form>

 <?php
else:
include("../inc/db.php");
dbConnect("a3m");

$sql = "INSERT INTO susreti SET
              datum = '$_POST&#1111;datum]',
              naslov = '$_POST&#1111;naslov]',
			  mjesto = '$_POST&#1111;mjesto]',
			  novost = '$_POST&#1111;novost]'";
mysql_query($sql);
$sql1 = "commit;";
mysql_query($sql1);

// pokupi zadnji ID

$sql3 = "select * from susreti ORDER BY ID DESC";
$res3 = mysql_query($sql3);
$zadnji_id = mysql_result($res3,0,'ID');

// SLIKE POÈETAK
$result_final = "";
	$counter = 0;

	// List of our known photo types
	$known_photo_types = array( 
						'image/pjpeg' => 'jpg',
						'image/jpeg' => 'jpg',
						'image/bmp' => 'bmp',
						'image/x-png' => 'png'
					);
	
	// GD Function List
	$gd_function_suffix = array( 
						'image/pjpeg' => 'JPEG',
						'image/jpeg' => 'JPEG',
						'image/bmp' => 'WBMP',
						'image/x-png' => 'PNG'
					);
	
	// Fetch the photo array
	$photos_uploaded = $_FILES&#1111;'photo_filename'];
	$a = 0;
	
	// UPLOAD SLIKA !!!!
// initialization

	
	

	while( $counter <= count($photos_uploaded) )
	&#123;
		if($photos_uploaded&#1111;'size']&#1111;$counter] > 0)
		&#123;
			if(!array_key_exists($photos_uploaded&#1111;'type']&#1111;$counter], $known_photo_types))
			&#123;
				$result_final .= "File ".($counter+1)." is not a photo<br />";
			&#125;
			else
			&#123;
				mysql_query( "INSERT INTO susreti_slike (`photo_filename`,`ID`) VALUES('0','$zadnji_id')" );
				$new_id = mysql_insert_id();
				$filetype = $photos_uploaded&#1111;'type']&#1111;$counter];
				$extention = $known_photo_types&#1111;$filetype];
				$filename = $new_id.".".$extention;

				mysql_query( "UPDATE susreti_slike SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );

				// Store the orignal file
				copy($photos_uploaded&#1111;'tmp_name']&#1111;$counter], $images_dir2."/".$filename);

				// Let's get the Thumbnail size
				$size = GetImageSize( $images_dir2."/".$filename );
				if($size&#1111;0] > $size&#1111;1])
				&#123;
					$thumbnail_width = 150;
					$thumbnail_height = (int)(150 * $size&#1111;1] / $size&#1111;0]);
				&#125;
				else
				&#123;
					$thumbnail_width = (int)(150 * $size&#1111;0] / $size&#1111;1]);
					$thumbnail_height = 150;
				&#125;
			
				// Build Thumbnail with GD 2.x.x, you can use the other described methods too
				$function_suffix = $gd_function_suffix&#1111;$filetype]; 
				$function_to_read = 'ImageCreateFrom' . $function_suffix; 
				$function_to_write = 'Image' . $function_suffix; 

				// Read the source file 
				$source_handle = $function_to_read($images_dir2 . '/' . $filename); 
        
				if ($source_handle) &#123; 
				 // Let's create a blank image for the thumbnail 
				 $destination_handle = 
 				  ImageCreateTrueColor($thumbnail_width, $thumbnail_height); 

				 // Now we resize it 
				 ImageCopyResampled($destination_handle, $source_handle,0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size&#1111;0], $size&#1111;1]); 
				&#125; 

				// Let's save the thumbnail 
				$function_to_write($destination_handle, $images_dir2 . '/tb_' . $filename);


				ImageDestroy($destination_handle );
				//

				$result_final .= "<img src='".$images_dir2. "/tb_".$filename."' /> File ".($counter+1)." Added<br />";
			&#125;
		&#125;
	$counter++;
	&#125;


// END UPLOAD SLIKA
	
	
	
// SLIKE KRAJ


echo ''.$_FILES&#1111;'photo_filename'].'';
//print "<META HTTP-EQUIV='Refresh' content='0;URL=susreti.php'>"; 
		  
?>

<?php
endif;
?>
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

What do you get if you echo this to the screen?

Code: Select all

echo count($photos_uploaded);
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Hi
I haven't really read your code but I came across this same problem - cannot upload more than 5 files !
The mistake I did was to count($_FILES['Photos']) which ALWAYS returns 5 because thats the total number or elements in the array - all the parameters for each file - size, tmp location, name etc.
count($_FILES['Photos']['name']) will return the total number of files for uploading
count($_FILES['Photos']['size']) or any other parameter for that matter.

Code: Select all

Mistake : for ($i=0;$i<count($_FILES&#1111;'Photos']);$i++)
Correct : for ($i=0;$i<count($_FILES&#1111;'Photos']&#1111;'name']);$i++)

From http://in2.php.net/manual/en/features.file-upload.php
The contents of $_FILES from the example form is as follows. Note that this assumes the use of the file upload name userfile, as used in the example script above. This can be any name.

$_FILES['userfile']['name']
The original name of the file on the client machine.
$_FILES['userfile']['type']
The mime type of the file, if the browser provided this information. An example would be "image/gif".
$_FILES['userfile']['size']
The size, in bytes, of the uploaded file.
$_FILES['userfile']['tmp_name']
The temporary filename of the file in which the uploaded file was stored on the server.
$_FILES['userfile']['error']
The error code associated with this file upload. This element was added in PHP 4.2.0
Granda
Forum Newbie
Posts: 7
Joined: Thu Mar 03, 2005 5:05 pm

Post by Granda »

Code: Select all

$photos_uploaded = $_FILES&#1111;'photo_filename'];
when i do

Code: Select all

echo count($photos_uploaded)
i get 5 !. thats why :

Code: Select all

while( $counter <= count($photos_uploaded) )
only uploads 6 files, tho it should upload 5, i event dont know why 6, but that doesent metter.

@anjanesh : Ill try with :

Code: Select all

$photos_uploaded = $_FILES&#1111;'photo_filename']&#1111;'name'];
Granda
Forum Newbie
Posts: 7
Joined: Thu Mar 03, 2005 5:05 pm

Post by Granda »

if i do this :

Code: Select all

for ($photos_uploaded=0;$photos_uploaded<count($_FILES&#1111;'photo_filename']&#1111;'name']);$photos_uploaded++)
it returnes 24?

dont know why...
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Check for blank file values (if a user has not entered any filename in a particular filetextbox)

Code: Select all

$uploadDir = 'photos/';
for ($i=0;$i<count($_FILES&#1111;'Photos']&#1111;'name']);$i++)
 &#123;
 	if ($_FILES&#1111;'Photos']&#1111;'name']&#1111;$i]!="")
 	 &#123;
 	 	$uploadFile = $uploadDir.$_FILES&#1111;'Photos']&#1111;'name']&#1111;$i];
 	 	move_uploaded_file($_FILES&#1111;'Photos']&#1111;'tmp_name']&#1111;$i],$uploadFile)
 	 &#125;
 &#125;
Last edited by anjanesh on Sat Mar 05, 2005 7:28 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'd use the error element for checking, rather than the name.
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

You get 6 because the while is counting from 0 to <=5. That is a total of 6 steps through the while loop.
Granda wrote:

Code: Select all

while( $counter <= count($photos_uploaded) )
only uploads 6 files, tho it should upload 5, i event dont know why 6, but that doesent metter.
Granda
Forum Newbie
Posts: 7
Joined: Thu Mar 03, 2005 5:05 pm

Post by Granda »

yup thx.

Problem solved with :

Code: Select all

count($_FILES&#1111;'Photos']&#1111;'name']);
24 is there because i have 24 boxes for file upload.

thx all.
Post Reply