Page 1 of 1

file uploading question

Posted: Wed May 11, 2005 11:20 am
by Jr
Ok... I have a file upload script that works just fine and uploads files no problem. The only thing is that it seems to have a file size limit or something. I want to be able to set the limit and upload files up to or over a gig in size. Is this possible with what I have below? Do I need to do it different maybe?

This is what i have for the form:

Code: Select all

print "<table width='$titlewide' $border>";
		print "<form enctype='multipart/form-data' action='upload.php' method='post'>"; //upload_send
		print "<input type='hidden' name='MAX_FILE_SIZE' value='943718400'>";
		print "<tr height='20px' bgcolor='$bgcolour10'>";
			IF ($rights_level == 9)
				{ print "<td align='center' width='40px'><font size='2' color='white'><b>Del</b></font></td>"; }
			print "<td width='10px'></td>";
			print "<td><a href='upload.php?sort=fn'><font size='2' color='white'><b>File Name</b></font></a></td>";
			print "<td><font size='2' color='white'><b>Ext.</b></font></td>";
			print "<td width='20px'></td>";
			print "<td><font size='2' color='white'><b>Type</b></font></td>";
			print "<td width='20px'></td>";
			print "<td align='right'><font size='2' color='white'><b>Size</b></font></td>";
			print "<td width='170px' align='right'><a href='upload.php?sort=ud'><font size='2' color='white'><b>Upload Date</b></font></a></td>";
			print "<td width='10px'></td>";
		print "</tr>";

This is what i have for the upload:

Code: Select all

/////////////  Get File Info.  \\\\\\\\\\\\\\
	$file_name = $_FILES['userfile']['name'];
	$file_type = $_FILES['userfile']['type'];
	$file_size = $_FILES['userfile']['size'];
	
	
	/////////////  Upload File Script  \\\\\\\\\\\\\\
	
	$set_time_limit = set_time_limit(90); // Change FTP time-out limit from 'default' 30 seconds to different time (in seconds)
	
	print "<table width='$titlewide'>";
	
		$uploaddir	=	'/directory/';
		$uploadfile	=	$uploaddir . basename($_FILES['userfile']['name']);
		
		IF ( $uploadfile != "" )
		{
			IF ( $file_size == 0 )
			{
				print "<table width='$titlewide' $border>";
					print "<tr height='160px'>";
						print "<td align='center'>";
								print "<b>Uploaded file has no file size</b>";
								print "<p>Want to go back to the <a href='upload.php'>upload/Download</a> page?";
						print "</td>";
					print "</tr>";
				print "</table>";
			}
					// 1 KB =			1,024 Bytes
					// 1 MB =		1,048,576 Bytes
					// 1 GB =	1,073,741,824 Bytes
			ELSEIF ( $file_size >= 3145728 ) // Current upload limit \\
			{
				print "<table width='$titlewide' $border>";
					print "<tr height='160px'>";
						print "<td align='center'>";
								print "<b>File size too large must be under 3mb</b>";
								print "<p>Want to go back to the <a href='upload.php'>upload/Download</a> page?";
						print "</td>";
					print "</tr>";
				print "</table>";
			}
			ELSEIF (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) // Upload File Here
			{
				
				/////////////  Insert File Info. into DB  \\\\\\\\\\\\\\
				$result = mysql_query("INSERT INTO files (file_name, file_type, file_size, upload_date) VALUES('$file_name', '$file_type', '$file_size', now())")
				or die(mysql_error());
				
				/////////////  Print File Info.  \\\\\\\\\\\\\\
				print "<table width='$titlewide' $border>";
					print "<tr height='40px'>";
						print "<td width='60px'></td>";
						print "<td width='100px'></td>";
						print "<td></td>";
						print "<td></td>";
					print "</tr>";
					print "<tr>";
						print "<td></td>";
						print "<td>File Name:</td>";
						print "<td>$file_name</td>";
						print "<td></td>";
					print "</tr>";
					print "<tr>";
						print "<td></td>";
						print "<td>File Type:</td>";
						print "<td>$file_type</td>";
						print "<td></td>";
					print "</tr>";
					print "<tr>";
						print "<td></td>";
						print "<td>File Size:</td>";
						print "<td>$file_size"." kb</td>";
						print "<td></td>";
					print "</tr>";
				print "</table>";
				
				print "<table width='$titlewide' $border>";
					print "<tr height='160px'>";
						print "<td align='center'>";
								print "<b>File Uploaded Successfully</b>";
								print "<p>Want to go back to the <a href='upload.php'>upload/Download</a> page?";
						print "</td>";
					print "</tr>";
				print "</table>";
			}
			ELSE
			{
				echo "Sorry, could not copy file into system.";
			}
		}
		ELSE
		{
			print "<tr><td>There is no file to upload</td></tr>";
		}
		print "</table>";
d11wtq | Please read the sticky about posting code in the forums :-D - USE

Code: Select all

tags!

Posted: Wed May 11, 2005 12:39 pm
by shiznatix
im sure its possible, you would have the change the file size hidden field on your form to a gig. also change max_file_size in your php.ini to a gig and also change your time out in seconds thing to like a billion in your php.ini because it would take forever to do that. but ya its possible

Posted: Wed May 11, 2005 12:55 pm
by Jr
My problem isn't really that I want to be able to upload gigs of stuff it's that I can't even upload 15 or 16mb. Either way though its something I have to change on the server though? Guessing I can't just do that myself can I?

Posted: Wed May 11, 2005 12:59 pm
by Chris Corbyn
It's an apache configuration issue. The default size is 15MB (I think :? ) . You'll need acess to the server to change it... Not sure that .htaccess will make a difference for this sort of thing.

Posted: Wed May 11, 2005 1:03 pm
by wwwapu
check the PHP manual
ini_set()
post_max_filesize ****
upload_max_filesize
set_time_limit()

Posted: Thu May 12, 2005 11:19 am
by Jr
ok, if my php.ini says my 'post_max_size' is 55M I should be able to upload up to 55mb if I set the set_time_limit() to an hour (3600 sec) or something shouldn't I? Does anyone have an example of this that works?

Posted: Thu May 12, 2005 11:34 am
by pickle
From the manual:

Code: Select all

<!-- MAX_FILE_SIZE must precede the file input field -->
    <input type=&quote;hidden&quote; name=&quote;MAX_FILE_SIZE&quote; value=&quote;30000&quote; />
You also need to set this value to > 15 MB, or you'll get a 'file too big' error.

Note that this is in addition to php.ini

Posted: Thu May 12, 2005 11:41 am
by Jr
I already have that and it doesn't work. (Sorry, guess I didn't post that initially). Also though I'm not getting my IF statement to return that the "file is too large" it tells me that the "file has no file size" (like the server wont let me upload it or something).

Posted: Thu May 12, 2005 11:57 am
by pickle
Have you tried multiple different files? That's happened to me before, and the problem wasn't my code, it was the file I was trying to upload.

Posted: Thu May 12, 2005 12:17 pm
by Jr
yes, I've tried different files (different sizes, etc). Everywhere I look everyone says the 'default' php.ini file upload is 2mb. I believe mine says 55mb (if I'm reading it correctly) but I dont know how to actually upload that or change it to let me upload that.

I have set_time_limit(4800) on the page that it posts to so I would think that that would get rid of any 'time' related issues. As I said before my php.ini says 55M for the post_max_size. So it seems that everything 'should' work. Dont know what to do :(

Posted: Thu May 12, 2005 1:23 pm
by wwwapu
If there is one thing which is affected by many other things, it would be file uploads...
PHP manual wrote:If memory limit is enabled by your configure script, memory_limit also affects file uploading. Generally speaking, memory_limit should be larger than post_max_size.
Default for memory_limit is 8M if I'm not mistaken.

Posted: Thu May 12, 2005 1:36 pm
by Jr
it wont even let me upload anything like 2.5mb much less 8mb.

Posted: Thu May 12, 2005 2:07 pm
by wwwapu
I'm repeating myself again, but did you check the manual on upload_max_filesize
PHP manual wrote:upload_max_filesize "2M" PHP_INI_SYSTEM|PHP_INI_PERDIR