Announcement

Collapse
No announcement yet.

Php -> file upload to mysql problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Php -> file upload to mysql problem

    hi i want to make upload script that can upload long files..
    so first i am creating a mysql tables

    PHP Code:
    CREATE TABLE upload (
         
    id INT NOT NULL AUTO_INCREMENT,
         
    name VARCHAR(30NOT NULL,
         
    type VARCHAR(30NOT NULL,
         
    size INT NOT NULL,
         
    content LONGBLOB NOT NULL,
         
    PRIMARY KEY(id)
         ); 
    THEN I AM CREATING THE PHP FILE


    PHP Code:
    <html>
    <head>
    <title>Upload File To MySQL Database</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    <!--
    .box {
        font-family: Arial, Helvetica, sans-serif;
        font-size: 12px;
        border: 1px solid #000000;
    }
    -->
    </style>
    </head>

    <body>
    <?
    if(isset($_POST['upload']))
    {
            
    $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);
            
    $content addslashes($content);
            
    fclose($fp);
            
            if(!
    get_magic_quotes_gpc())
            {
                
    $fileName addslashes($fileName);
            }
            

            include 
    'library/config.php';
            include 
    'library/opendb.php';
            
            
    $query "INSERT INTO upload (name, size, type, content ) ".
                     
    "VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

            
    mysql_query($query) or die('Error, query failed');                    
            include 
    'library/closedb.php';
            
            echo 
    "<br>File $fileName uploaded<br>";
    }        
    ?>
    <form action="" method="post" enctype="multipart/form-data" name="uploadform">
      <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
        <tr> 
          <td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="900000000"><input name="userfile" type="file" class="box" id="userfile">
             </td>
          <td width="80"><input name="upload" type="submit" class="box" id="upload" value="  Upload  "></td>
        </tr>
      </table>
    </form>
    </body>
    </html>

    So i don't get problems when i am uploading smaller files SMALLER THEN 1mb
    and when i am uploading large files (LARGER THEN 1MB) and SMALLER THEN 10mb
    i am getting this error


    Warning: fread(): supplied argument is not a valid stream resource in xxx\xxx\xxx\upload.php on line 26
    Warning: fclose(): supplied argument is not a valid stream resource in xxx\xxx\xxx\upload.php on line 28
    AND WHEN I AM UPLOADING FILES LARGER THEN 10 MB I don't get anything .. no errors nothing and NO INFORMATIONS TO THE DATABASE.. SIMPLY DON'T WANT TO UPLOAD :s

    Please help

  • #2
    The error message was probably surpressed by php.ini setting, or you've got prior configurations on error_reporting() which told it to not show. But generally speaking, from the errors after, it implies that php was unable to open the file, so the stream was invalid...

    Check your phpinfo() for max upload size, I think your host may have it set to something very small... Also check for memory limit... it might be under 10mb so there's "no error" (php died before it could output anything).
    Best Regards,
    Andy Huang

    Comment

    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
    Working...
    X