Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how upload files up 1mb in to mysql database?

Posted on 2007-03-18
11
Medium Priority
?
258 Views
Last Modified: 2013-12-13
hi all
how to upload files up 1mb such as 100mb and save this file in mysql database as binary field (BLOB)?

i try , but the form don't upload up 1mb in database

please see me any examples
i use this codes:
after submit :

            file_mime= $_FILES['userfile']['type'];
            $file_name= $_FILES['userfile']['name'];
            $file_size= $_FILES['userfile']['size'];
                  
if (!empty($file_name)){                  
                  
            $fp = fopen($_FILES['userfile']['tmp_name'], "rb");
            while(!feof($fp))
            {
            $file_contents .= fread($fp, 1024);  //fread is binary safe
            }
            fclose($fp);
            $file_contents = addslashes($file_contents);
            $file_contents = addcslashes($file_contents, "\0");

$sql="INSERT INTO email (user_send, user_recived, msg_title, msg_body, msg_date, file_mime, file_contents, file_name, file_size) VALUES ('$user_id', '$str1', '$msg_title', '$msg_body','$msg_date', '$file_mime', '$file_contents', '$file_name', $file_size)";
        $qq=mysql_query($sql);

i think the problem in apache ,

thanks for all
0
Comment
Question by:aymansoft
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
11 Comments
 
LVL 9

Expert Comment

by:richdiesal
ID: 18744423
What error are you getting that you're trying to diagnose?  Does the SQL query run fine, but the data is corrupt?  My instinct is that you're trying to put a 1MB+ file into a BLOB field, which is far too small to hold it (a BLOB only holds around 65k).  Try changing the BLOB to a MEDIUMBLOB (16MB) or LONGBLOB (4GB).  If that doesn't fix it, I need more information about your problem.
0
 
LVL 24

Accepted Solution

by:
glcummins earned 252 total points
ID: 18747559
Additionally, you need to make sure your server is configured to handle the upload of large files. Check your php.ini file for a line like:

upload_max_filesize = 2M

You will need to change this to fit your needs. Remember to restart your webserver after changing this value.
0
 
LVL 1

Author Comment

by:aymansoft
ID: 18751587
hi experts

i try the change value upload_max_filesize=128M

and i use largblob but i cannot to save file in database ,
I get this infinite warning message in the post page

Warning: feof(): supplied argument is not a valid stream resource in c:\appserv\www\localemail\newemail.php on line 142

Warning: fread(): supplied argument is not a valid stream resource in c:\appserv\www\localemail\newemail.php on line 144

please help me
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 24

Expert Comment

by:glcummins
ID: 18751805
Sounds like your script is trying to find the uploaded file at an incorrect location. Are you able to show us your code around lines 125-160 so we can see what is happening?
0
 
LVL 9

Expert Comment

by:richdiesal
ID: 18752862
His script is posted above.

But another note: you also don't need to parse the file line by line in order to pass it to SQL.  Try changing the following lines:
while(!feof($fp))
            {
            $file_contents .= fread($fp, 1024);  //fread is binary safe
            }

To this:
$file_contents = addslashes(fread($fp, fileSize($_FILES['userfile']['tmp_name'])));

Otherwise, your code looks fine.  Are you sure that Apache has read access to the folder where temp files are stored?   Try to add "echo $_FILES['userfile']['tmp_name']l" in that script and see what the value is.
0
 
LVL 1

Author Comment

by:aymansoft
ID: 18767509
it print
C:\WINDOWS\system32\config\SYSTEM~1\LOCALS~1\Temp\php160.tmp
0
 
LVL 9

Expert Comment

by:richdiesal
ID: 18767728
Let's double-check something.

Change:
$fp = fopen($_FILES['userfile']['tmp_name'], "rb");

to:
$fp = fopen($_FILES['userfile']['tmp_name'], "rb") or die("Could not open file.");

0
 
LVL 1

Author Comment

by:aymansoft
ID: 18774256
it open the tmp_name no error hear
0
 
LVL 9

Assisted Solution

by:richdiesal
richdiesal earned 248 total points
ID: 18775014
Did you try changing:
while(!feof($fp))
            {
            $file_contents .= fread($fp, 1024);  //fread is binary safe
            }

To this:
$file_contents = fread($fp, fileSize($_FILES['userfile']['tmp_name']));
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question