-1

I've been using PHP upload file into MySQL database. But I noticed that I can only upload files not exceeding 6MB.

How can I increase the upload size? Up to what size am I able to upload file?

Below is my PHP file.

index.php

<?php

    mysql_connect("127.0.0.1","Localhost"," ");
    mysql_select_db("uploadfile");

    if(isset($_POST['submit']))
    {
        $name = $_FILES['file']['name'];
        $temp = $_FILES['file']['tmp_name'];

        move_uploaded_file($temp,"uploaded/".$name);
        $url = "http://127.0.0.1/file/uploaded/$name";
        mysql_query("INSERT INTO `file` VALUE ('','$name','$url')");
    }

    ?>
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>File Upload</title>
    </head>

    <body>

    <a href="file.php">Show File</a>
    <form action="index.php" method="POST" enctype="multipart/form-data">
        <input type="file" name="file" />
        <input type="submit" name="submit" value="Upload!" />
    </form>

    <?php

    if(isset($_POST['submit']))
    {
        echo "<br />".$name." has been uploaded";
    }

    ?>

    </body>
    </html>

file.php

  <?php

    mysql_connect("127.0.0.1","Localhost"," ");
    mysql_select_db("uploadfile");

    ?>
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>File Upload</title>
    </head>

    <body>

    <?php

    $query = mysql_query("SELECT * FROM `file`");
    while($row = mysql_fetch_assoc($query))
    {
        $id = $row['id'];
        $name = $row['name'];

        echo "<a href='watch.php?id=$id'>$name</a><br />";
    }

    ?>

    </body>
    </html>
Logan Wayne
  • 6,001
  • 16
  • 31
  • 49

4 Answers4

1

Edit your php.ini with these value.

; Maximum allowed size for uploaded files. 
upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize 
post_max_size = 40M

I think this question is already answered here: PHP change the maximum upload file size

Community
  • 1
  • 1
Miraj
  • 326
  • 3
  • 17
0

You could try and use this

ini_set('upload_max_filesize', '10M');

This will set the max filesize to 10 Megabytes you can ofcourse change the number to your liking

This is where i found the answer awhile ago myself: Upload large files

RedBaron
  • 4,717
  • 5
  • 41
  • 65
Eli
  • 1
0

Try configuring your php.ini file which can be found by opening your Control Panel. Click Config of your Apache, and select PHP (php.ini). Search for the keyword upload_max_filesize=. You can change the max file size in your system. Save and close. If still didn't work. Try restarting your Apache.

Your second option is having ($_FILES["file"]["size"]<$uploadsize) on your upload condition. Just change the $uploadsize variable to your preferred size.

Logan Wayne
  • 6,001
  • 16
  • 31
  • 49
0

You need to configure php.ini. The values should changed as follows:

; Maximum allowed size for uploaded files.
upload_max_filesize = 8MB

; Must be greater than or equal to upload_max_filesize
post_max_size = 8MB

The default as in your case may be set to 2MB, if I am not wrong. The following link will give you a clear picture.

http://php.net/manual/en/ini.core.php

Vagabond
  • 877
  • 1
  • 10
  • 23