How to upload files above 1 MB in size?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chirag narula
    New Member
    • Dec 2010
    • 1

    How to upload files above 1 MB in size?

    Hello,
    I am working on a site currently. And I did make it live but I had to put it off due to this problem I found. I saw other threads with kind of same problem as well but nothing seems to solve mine.
    Here the php code I am using to upload files.
    Code:
     </TR>
    <tr>
    <td><h3>File: </h3></td>
    <td width="200">
    <input type="hidden" name="MAX_FILE_SIZE" value="20000000">
    <input name="userfile" type="file" id="userfile">
    </td>
    <td width="50"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
    </tr>
    </table>
    </form>
    <?php
    if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
    {
    $description = $_REQUEST['description'];
    $cat = $_POST['Category'];
    
    $fileName = $_FILES['userfile']['name'];
    $tmpName  = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];
    $fp      = fopen($tmpName, 'r');
    $content = fread($fp, filesize($tmpName));
    $content = addslashes($content);
    fclose($fp);
    if(!get_magic_quotes_gpc())
    {
      $fileName = addslashes($fileName);
    }
    $query = "INSERT INTO upload (name, size, type, content, description, username, category) ".
    "VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$description', '$name', '$cat')";
    mysql_query($query) or die('Error, query failed');
    
    echo "<br>Hurray!!!File $fileName has been successfully uploaded..Upload another file or go back to home<br>";
    This is the part responsible for the uploading of the files. So when I upload files with size less than 1 MB . they do get uploaded in the database table. I am using Longblob. But when I try to upload files with size more than that.. I get the "Error, query failed" message.

    I checked the php.ini settings and the values are-
    max_execution_t ime 300 --> in case it take too long to upload
    post_max_size = 128 M
    upload_max_file size = 28 M
    memory_limit = 128M

    What could be wrong?
    TIA
    Chirag Narula
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Try printing the error with mysql_error(). That should give you a better clue.


    Dan

    Comment

    Working...