Jump to content

PHP Uploading only KB size..


vinsux

Recommended Posts

my file upload only accepts kilobytes(kb)..

 

if i upload 1000kb.. it doesn't prompot anything..

 

 

PLS HELP ME.. This is the main concept of my website.. i need to finish it.. Y_Y

 

 

 

	<form method="post" enctype="multipart/form-data">
		<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
		<tr> 
		<th width="246">
		<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
		<input name="userfile" type="file" id="userfile"> 
		</th>
		<th width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></th>
		</tr>
		</table>
		</form>
<?php
date_default_timezone_set('Asia/Hong_Kong');
$date = date('m/d/Y h:i:s a', time());
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}

$con = mysql_connect("localhost","root","");

if(!$con)
{
    die("could not connect to server".mysql_error());
}

mysql_select_db("files", $con);
$query = "INSERT INTO upload (name, size, type, content, time ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$date')";

mysql_query($query) or die('Error, query failed'); 
mysql_close($con);

echo "<br>File $fileName uploaded<br> <a href='fcsci01.php'>Click Here to view the download page</a>";
} 

?>

 

 

 

the structure of my database is like this:

 

table name: upload

 

id: int(11)

name: varchar(50)

type: varchar(30)

size: bigint(60)

content: longblob

time: varchar(25)

Link to comment
Share on other sites

  • 2 weeks later...

I think the error is on my sql..

 

i do anything in PHP.ini and it didn't help me..

 

pls. pls.. help me...

 

<?php echo "Notes:<br><br>";
						echo "<li>File upload limit: 24mb<br><br></li>";
						echo "<li>Only accepting .docx, .xlsx, .pptx, .txt<br><br><br></li>"?> 
		<form method="post" enctype="multipart/form-data">
 	    <input type="hidden" name="MAX_FILE_SIZE" value="25000000" />
		<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
		<tr> 
		<th width="246">
		<input name="userfile" type="file" id="userfile"> 
		</th>
		<th width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></th>
		</tr>
		</table>
		</form>
<?php
date_default_timezone_set('Asia/Hong_Kong');
$date = date('m/d/Y h:i:s a', time());
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}

if((!empty($_FILES["userfile"])) && ($_FILES['userfile']['error'] == 0)) {
$fname = basename($_FILES['userfile']['name']);
$ext = substr($fname, strrpos($fname, '.') + 1);
if (($ext == "exe") && ($_FILES["userfile"]["size"] < 25000000)){
		die("Warning: Cannot accept .exe files and larger than 25mb");
}
}

$con = mysql_connect("localhost", "root","");

if(!$con)
{
    die("could not connect to server".mysql_error());
}

mysql_select_db("files", $con);
$query = "INSERT INTO upload (name, size, type, content, time ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$date')";

mysql_query($query) or die('Error, query failed'); 
mysql_close($con);

echo "<br>File $fileName uploaded<br> <a href='fcsci01.php'>Click Here to view the download page</a>";
} 

?>

Link to comment
Share on other sites

IF you're grabbing large data through a query, you need to make sure max_allowed_packet is big enough. Sure enough it defaults to 1meg.

 

http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_allowed_packet

 

There's also mysqli_stmt_send_long_data but I'm not sure if it works on SELECTs as well.

 

edit - Nevermind about the send_long_data - From the manual

On the client side, max_allowed_packet has a default of 1GB.
Link to comment
Share on other sites

Do you get any sql errors, and if so what errors do you get?

Replace die('Error, query failed') with die(mysql_error())

 

thank you very much.. it worked now...

 

my only problem is it doesn't display an error message if the file size is 25mb or larger..

this is the filesize code.. is it correcT??

if the file is exe... it prompts an error message but if the file is larger than 25mb, it doesn't prompt an error message..

 

 

$fileSize = $_FILES['userfile']['size'];


if((!empty($_FILES["userfile"])) && ($_FILES['userfile']['error'] == 0)) {
$fname = basename($_FILES['userfile']['name']);
$ext = substr($fname, strrpos($fname, '.') + 1);
if (($ext == "exe") && ($fileSize <= 25000000)){
		die("Warning: Cannot accept .exe files and larger than 25mb");
}
}

 

 

again.. thank you very much for all your help!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.