abdulqadir Posted November 24, 2010 Share Posted November 24, 2010 I've made a upload script which uploads files upto 1GB and it works like this. It takes the values of name,size, type from the $_FILES function and stores it to one of the tables of mysql. The problem is that the value which stores in the "size" column is always 9999.99 irrespective of the filesize. I've choosen decimal (6,2) as datatype for the size column. Note: I've divided the $_FILE['file']['size'] by 1048576 to convert the filesize from Bytes to Mega Bytes. Here's my upload code though i'm pretty much sure that the upload code is fine. The problem is with the datatype. <?php $uploaddir = "d:/server_uploads/"; if((isset($_POST['upload'])) && (($_FILES['file']['type']== "video/x-matroska") || ($_FILES['file']['type']== "video/mpeg") || ($_FILES['file']['type']== "video/avi")|| ($_FILES['file']['type']== "video/vnd.rn-realvideo") || ($_FILES['file']['type']== "video/vnd.rn-realvideo")|| ($_FILES['file']['type']== "application/octet-stream")|| ($_FILES['file']['type']== "audio/mpeg")) && ($_FILES["file"]["size"] > 1048576)) { $fileName = $_FILES['file']['name']; $tmpName = $_FILES['file']['tmp_name']; $fileSize = $_FILES['file']['size']; $fileType = $_FILES['file']['type']; $filePath = $uploaddir . $fileName; $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "Error uploading file"; exit; } echo "Your file has been uploaded succesfully!! Below are details: <br />"; echo "File: ". $_FILES['file']['name'] . " <br />"; echo "Type: ". $_FILES['file']['type'] . " <br />"; echo "Size: ". ($_FILES['file']['size'] / 1048576) . " MB<br />"; } else { echo "Filtype is not supported"; exit; } $con = mysql_connect ("localhost:3306", "root", ""); mysql_select_db ("server", $con); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } if ($fileName!="") { $query = "INSERT INTO uploads (name, type, size, path ) " . "VALUES ('$fileName', '$fileType', '$fileSize', '$fileName')"; mysql_query($query); } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/219725-which-data-type-to-store-filesize/ Share on other sites More sharing options...
jdavidbakr Posted November 24, 2010 Share Posted November 24, 2010 In your code sample you're only dividing the file size by 1048576 as you echo it, you're not doing the conversion to the actual variable you're inserting into the database... Quote Link to comment https://forums.phpfreaks.com/topic/219725-which-data-type-to-store-filesize/#findComment-1139093 Share on other sites More sharing options...
jim_keller Posted November 24, 2010 Share Posted November 24, 2010 as jdavidbakr mentioned above, you're not dividing your final variable before it goes into the database. You don't really have to, though. Just use a BIGINT UNSIGNED, which will hold values from 0 to 18446744073709551615, and store the size in bytes. You also won't need a decimal digit in a field that stores the filesize. You can read about the mySQL numeric types here: http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html Quote Link to comment https://forums.phpfreaks.com/topic/219725-which-data-type-to-store-filesize/#findComment-1139132 Share on other sites More sharing options...
abdulqadir Posted November 25, 2010 Author Share Posted November 25, 2010 Thank you very much jdavidbakr and jim_keller for your replies. I'm so stupid. The problem is solved. I've divided $fileSize by 1048576 and the values are stored correctly now. Thanx again! Quote Link to comment https://forums.phpfreaks.com/topic/219725-which-data-type-to-store-filesize/#findComment-1139347 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.