473,419 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

store images in database using php

Hello and thank you.

Could you please help me with this.:
i try to store images using the following code,
and it just bring a blank screen.
i being trying different things and i am not sure if the problem is on values.
Please help me. PUT YOUR CODE WITHIN code OR php TAGS NEXT TIME!!!!
Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <form action="insert2.php"method="post" enctype="multipart/form-data">
  3. Select Image File: <input type="file" name="userfile" size="40"><input type="submit" value="submit">
  4. </form>
  5.  
  6. =======
  7. insert2.php:
  8.  
  9. </body>
  10. <body>
  11. <?php
  12. $conn = mysql_connect("localhost", "root") 
  13.   OR DIE (mysql_error());
  14. @mysql_select_db ("image", $conn) OR DIE (mysql_error());
  15.  
  16. // Do this process if user has browse the 
  17. // file and click the submit button
  18. if ($_FILES) {
  19.   $image_types = Array ("image/bmp",
  20.                         "image/jpeg",
  21.                         "image/pjpeg",
  22.                         "image/gif",
  23.                         "image/x-png");
  24.   if (is_uploaded_file ($_FILES[“userfile”][“tmp_name”])) {
  25.     $userfile  = addslashes (fread 
  26.                  (fopen ($_FILES["userfile"]["tmp_name"], "r"), 
  27.                  filesize ($_FILES["userfile"]["tmp_name"])));
  28.     $file_name = $_FILES["userfile"]["name"];
  29.     $file_size = $_FILES["userfile"]["size"];
  30.     $file_type = $_FILES["userfile"]["type"];
  31. if (in_array (strtolower ($file_type), $image_types)) {
  32. $sql = "INSERT INTO image "
  33. . "(image_type, image, image_size, image_name, image_date) ";
  34. $sql.= "VALUES (";
  35. $sql.= "'{$file_type}', '{$userfile}', '{$file_size}', "
  36. . "'{$file_name}', NOW())";
  37. @mysql_query ($sql, $conn);
  38. Header("Location:".$_SERVER["PHP_SELF"]);
  39. exit();
  40. }
  41. }
  42. }
  43. </body>
PUT YOUR CODE WITHIN code OR php TAGS NEXT TIME!!!!
Oct 5 '06 #1
1 6641
ronverdonk
4,258 Expert 4TB
Before going into this, some questions:

- what have you done to isolate the problem?
- have you put traces in (such as echo's)?
- until what point in your code is everything processing ok?

Ronald :cool:
Oct 7 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: cover | last post by:
The question is, we have two options to store images, either in a Database (MySQL, Postgres, ...) like blob data, or in the hard disk the file and the path in database. Which option is better?...
1
by: Universal | last post by:
store Images (or any Binary Data) to a SQL Server database using VC++ Can anybody help me in this Thanks in advance
3
by: DL | last post by:
Hi, Many questions have already been asked and answered about images in Access... But despite having searched, I have not found an answer to the following question... In my DB, several forms...
2
by: Tim Zych | last post by:
How would I go about storing data files on my web host? I have an Access database driven website and I would like to save files and be able to download them. Can somebody point me in the right...
1
by: john_20_28_2000 | last post by:
Using asp.net, c#, mysql or SQL Server. I have a image uploading and wanted it to be "secure." Each user has their own section to login and upload images. Should I store the images in a database...
6
by: Rudy | last post by:
Hello all! I am amazed how many posts I have read to store an image in SQL, and just as many against it. So I learned how to store an image in a SQL db and retrieve the image. A little tricky,...
0
by: Skiran | last post by:
Hi to everybody, I am handling a large-scale project of MIS (Marketing information System). I am using Vb 6 as front end, Ms Access as back end and Crystal report 8 as reporting tool. 1)...
4
by: vunet.us | last post by:
I want to know if this practice is effective and secure: I have been thinking about storing some data, which my users upload, in text files rather than database, since often I do not know how much...
6
by: Keith Hughitt | last post by:
Hi all, I've run into a strange error while trying to store some PNG images in a MySQL database using MySQLdb. When I try to insert smaller images (< 64kb or so) everything seems to work fine....
2
by: gm000 | last post by:
hi i m using radiobuttonlist with images like this <asp:RadioButtonList ID="rbtnthumb1" runat="server"> <asp:ListItem Value ="News_icon.jpg"> <img...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.