0

I am working on a simple upload script. The thing is that when I upload an image file it is easily uploaded on the server and its data is written in my database but when I try to upload video files like mp4, and audio mp3 file, the server gives me this error.

https://i.stack.imgur.com/FCq2c.png

Here is my upload.php code.

<?php
include('config.php');
function bytesToSize1024($bytes, $precision = 2) {
    $unit = array('B','KB','MB');
    return @round($bytes / pow(1024, ($i = floor(log($bytes, 1024)))), $precision).' '.$unit[$i];
}

$FileName = $_FILES['filename']['name'];
$FileType = $_FILES['filename']['type'];
$FileSize = bytesToSize1024($_FILES['filename']['size'], 1);
$Fileid = uniqid(rand());
$query2 = "INSERT INTO files (id, name, size, type) VALUES ('$Fileid', '$FileName', '$FileSize '$FileType')";
    $result2 = mysql_query($query2);

echo <<<EOF
<p>Your file: {$FileName} has been successfully received.</p>
<p>Type: {$FileType}</p>
<p>Size: {$FileSize}</p>
EOF;

Here is my index.html code

<form action="upload.php" method="post" enctype="multipart/form-data">
                        <center><p> <input type='file' size='58' style='height: 30px; font-size: 18px' name='filename'></p>

                        <input type="submit" name="submit" value="Upload">              
                        </form>
  • Have you done a `print_r($_FILES);` to find out what yo actually have in `$_FILES`? – Carsten Massmann Sep 04 '13 at 10:54
  • check it by trying `print_r($_FILES);` what you are getting.. – Shaunak Shukla Sep 04 '13 at 10:57
  • Here is what I get........ Array ( [filename] => Array ( [name] => HTML5 tests - video.MP4 [type] => [tmp_name] => [error] => 1 [size] => 0 ) ) – user2354128 Sep 04 '13 at 10:59
  • Here is what I get while uploading a video. Array ( [filename] => Array ( [name] => Chrysanthemum.jpg [type] => image/jpeg [tmp_name] => C:\wamp\tmp\php73CA.tmp [error] => 0 [size] => 879394 ) ) – user2354128 Sep 04 '13 at 11:00
  • 1
    On the first print_r you gave us the error is 1, meaning the file is too big. http://php.net/manual/en/features.file-upload.errors.php – Ben Fortune Sep 04 '13 at 11:08

1 Answers1

0

Are the video files more then the max upload filesize of 2 Mb (default). PHP change the maximum upload file size

Community
  • 1
  • 1
Jasper
  • 534
  • 3
  • 11