vinsux Posted July 28, 2012 Share Posted July 28, 2012 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) Quote Link to comment https://forums.phpfreaks.com/topic/266384-php-uploading-only-kb-size/ Share on other sites More sharing options...
scootstah Posted July 28, 2012 Share Posted July 28, 2012 What does $_FILES['userfile']['error'] yield? Quote Link to comment https://forums.phpfreaks.com/topic/266384-php-uploading-only-kb-size/#findComment-1365069 Share on other sites More sharing options...
vinsux Posted August 12, 2012 Author Share Posted August 12, 2012 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/266384-php-uploading-only-kb-size/#findComment-1368756 Share on other sites More sharing options...
jazzman1 Posted August 12, 2012 Share Posted August 12, 2012 You want to record a file as binary, right ? What type the content column is ? Quote Link to comment https://forums.phpfreaks.com/topic/266384-php-uploading-only-kb-size/#findComment-1368760 Share on other sites More sharing options...
vinsux Posted August 12, 2012 Author Share Posted August 12, 2012 longblob sir Quote Link to comment https://forums.phpfreaks.com/topic/266384-php-uploading-only-kb-size/#findComment-1368770 Share on other sites More sharing options...
jazzman1 Posted August 12, 2012 Share Posted August 12, 2012 Do you get any sql errors, and if so what errors do you get? Replace die('Error, query failed') with die(mysql_error()) Quote Link to comment https://forums.phpfreaks.com/topic/266384-php-uploading-only-kb-size/#findComment-1368774 Share on other sites More sharing options...
xyph Posted August 12, 2012 Share Posted August 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266384-php-uploading-only-kb-size/#findComment-1368788 Share on other sites More sharing options...
Christian F. Posted August 12, 2012 Share Posted August 12, 2012 Have you tried dumping the finished SQL query, and made sure that it's correct? Quote Link to comment https://forums.phpfreaks.com/topic/266384-php-uploading-only-kb-size/#findComment-1368817 Share on other sites More sharing options...
vinsux Posted August 13, 2012 Author Share Posted August 13, 2012 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/266384-php-uploading-only-kb-size/#findComment-1368889 Share on other sites More sharing options...
xyph Posted August 13, 2012 Share Posted August 13, 2012 You want to use OR || not AND && Quote Link to comment https://forums.phpfreaks.com/topic/266384-php-uploading-only-kb-size/#findComment-1368977 Share on other sites More sharing options...
scootstah Posted August 13, 2012 Share Posted August 13, 2012 You want to use OR || not AND && For clarity, on this line: if (($ext == "exe") && ($fileSize <= 25000000)){ EDIT: By the way, that is a terrible way for a file type check. Use the mime type, not the file name. Check out fileinfo. Quote Link to comment https://forums.phpfreaks.com/topic/266384-php-uploading-only-kb-size/#findComment-1369028 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.