0

Hi all..i have a problem that i want to upload file less than 5MB..but it doesn't work for file size more than 3MB..what happen huh? Please help me..

<?php

include "connection/db_connect.php";
include "template.php";
$reqid=$_GET['reqid'];

 if (($_FILES["file"]["type"])
 && ($_FILES["file"]["size"] < 5000000000000))
   {
   if ($_FILES["file"]["error"] > 0)
     {
     echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
     }
   else
     {
     $filename = $_FILES["file"]["name"];
     $filetype =  $_FILES["file"]["type"];
     $size =  ($_FILES["file"]["size"]/ 1024);
     $path =  $_FILES["file"]["tmp_name"];
	 $dir = "upload/" . $_FILES["file"]["name"];
	 
	 $query = "INSERT INTO attachment (reqid, fileName, size, fileType,tmpName ) ".
			  "VALUES ('$reqid', '$filename', '$size', '$filetype', '$dir')";

	 mysql_query($query) or die('Error, query failed : ' . mysql_error());
 
    if (file_exists("upload/" . $_FILES["file"]["name"]))
       {
       echo  "<script language='javascript'>alert('Sorry! File already exists. Please change the filename' );</script>";
       }
     else
       {
       move_uploaded_file($_FILES["file"]["tmp_name"],
       "upload/" . $_FILES["file"]["name"]);
       echo $dir;
       }
     }
   }
 else
   {
   echo "<script language='javascript'>alert('Sorry!! File should be less then 5MB!');</script>"; 
   }
 
 ?>
3
Contributors
15
Replies
16
Views
5 Years
Discussion Span
Last Post by HasNor
Featured Replies
  • 1
    jkon 506   5 Years Ago

    Just maths You say [CODE]$_FILES["file"]["size"] < 5000000000000)[/CODE] And then [CODE]$size = ($_FILES["file"]["size"]/ 1024);[/CODE] So size could be 5000000000000/1024 which is 4882812500 so it isn’t 5 digits number … Read More

0

Well it doesn’t work, what is the message? … Have you checked your php.ini for max upload file size ?

0

Sometime it show error

Error, query failed : Data too long for column 'size' at row 1

0

Thanks for reply "jkon"

erm...sorry..how can i check it??

0

Well my friend, the message is telling you what is wrong , Data too long for column 'size' . What is the result of “SHOW CREATE TABLE attachment” that you defined the column 'size' ?

0

i define the column 'size' 5.. because i don't want it show longer size (exp : 543.8789789) actually the file size that i want to upload is 3582KB.. but not allowed to upload..

0

Thanks for reply "Karthik_pranas"...
i use varchar(5)

1

Just maths
You say

$_FILES["file"]["size"] < 5000000000000)

And then

$size =  ($_FILES["file"]["size"]/ 1024);

So size could be 5000000000000/1024 which is 4882812500 so it isn’t 5 digits number …

Votes + Comments
0

hurm.. than i change my code but still not work for file 3582KB..

if (($_FILES["file"]["type"])
 && ($_FILES["file"]["size"] < 5000000))
0

to both of you..
now i change my code n data size for table attachment to varchar(15)

i work but for file 3000Kb and above doesn't work..hurm..

if (($_FILES["file"]["type"])
 && ($_FILES["file"]["size"] < 5000000))
0

OMG!! i have solved my problem, actually i need to change the max file size in php.ini.. TQVM for help.. :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.