Solved

how upload files up 1mb in to mysql database?

Posted on 2007-03-18
11
254 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 63 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
Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all 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 62 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 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