0

My PHP code will only upload small files eg, 20mb so when I try to upload files that are more than that then it will say return nothing but it will insert into the database anyway. I have tried putting the upload size up but it Doesn't do anything. The script should upload a swf file and image while inserting the information into the database to be used. Why can't it upload more than 20mb.

<?php
$link = $_POST['link'];

if(isset($_POST['upload'])) {

$allowed_filetypes = array('.swf');
$max_filesize = 999999999999999999999999999999999999999999999;
$upload_path = 'swf/';
$game = $_POST['game'];
$category = $_POST['category'];
$swf = $_POST['swf'];
$height = $_POST['height'];
$width = $_POST['width'];
$radio=".swf";



$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$done = '';
for ($i = 0; $i < 25; $i++)
$done .= $characters[mt_rand(0, 61)];   
$filename = $done . '' . $radio;

$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);

if(!in_array($ext,$allowed_filetypes))
  die('The file you attempted to upload is not allowed');

if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
  die("The file you attempted to upload is too large");

if(!is_writable($upload_path))
  die('You cannot upload to the specified directory, please CHMOD it to 777. ');

if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) {
   $query = "INSERT INTO image (title, description) VALUES ($filename, $description)"; 
   mysql_query($query);

echo 'Game Added Successfully';
$doney = $website . '' . $filename;
echo "<br/>";
echo $doney;
$result = $upload_path . '' . $filename;
} else {
     echo 'There was an error during the file upload.  Please try again Later.';



}
}

?>
<br/>
<?php
if(isset($_POST['upload'])) {

$allowed_filetypes = array('.jpg');
$max_filesize = 999999999999999999999999999999999999999999999999999999;
$upload_path = 'gameimg/';
$game = $_POST['game'];
$category = $_POST['category'];
$swf = $_POST['swf'];
$height = $_POST['height'];
$width = $_POST['width'];
$radio=".jpg";



$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$done = '';
for ($i = 0; $i < 25; $i++)
$done .= $characters[mt_rand(0, 61)];   
$filename = $done . '' . $radio;
$link="/game?id=".$done;
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);

if(!in_array($ext,$allowed_filetypes))
  die('The file you attempted to upload is not allowed');

if(filesize($_FILES['filez']['tmp_name']) > $max_filesize)
  die("The file you attempted to upload is too large");

if(!is_writable($upload_path))
  die('You cannot upload to the specified directory, please CHMOD it to 777.');

if(move_uploaded_file($_FILES['filez']['tmp_name'],$upload_path . $filename)) {
   $query = "INSERT INTO image (title, description) VALUES ($filename, $description)"; 
   mysql_query($query);

echo 'Game Added Successfully';
$doney = $website . '' . $filename;
echo "<br/>";
echo $doney;
$resulty = $upload_path . $filename;
} else {
     echo 'There was an error during the file upload.  Please try again Later.';



}
}

?>
Chikn
  • 23
  • 8
  • 1
    Have you checked your `upload_max_filesize` and `post_max_size`? – ᴍᴇʜᴏᴠ Oct 08 '14 at 14:24
  • Also check the webserver's limits like @ceejayoz suggested. – ᴍᴇʜᴏᴠ Oct 08 '14 at 14:27
  • Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). [This article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide. – Jay Blanchard Oct 08 '14 at 14:37

1 Answers1

2

Clearly, your server does not support large files. Use phpinfo(); to see the contents of the php.ini file. Check the upload_max_filesize in your phpinfo(). This is located under the Core section of the php info.

EDIT : Also check the post_max_size which is also located under the Core section of the phpinfo (Pointed out in the comments by @TheSexiestManinJamaica ). And also check the post_max_size as pointed out in the comments again by @ceejayoz

Deval Khandelwal
  • 3,458
  • 1
  • 27
  • 38