473,382 Members | 1,784 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,382 software developers and data experts.

problem to store and retrive image in php

The below code can't take the images.plz tell that what is the problem in that code
[php]
<?php

// Connect to database

$errmsg = "";
if (! @mysql_connect("localhost","root","sreeni")) {
$errmsg = "Cannot connect to database";
}
@mysql_select_db("my_db1");

// First run ONLY - need to create table by uncommenting this
// Or with silent @ we can let it fail every sunsequent time ;-)

$q = <<<CREATE
create table pix (
pid int primary key not null auto_increment,
name varchar(20),email varchar(30),city varchar(20),state varchar(20),zip int(7),country varchar(20),month varchar(20),date int(3),imgdata longblob)
CREATE;
@mysql_query($q);

// Insert any new image into database
if ($_REQUEST[completed] == 1) {
// Need to add - check for large upload. Otherwise the code
// will just duplicate old file ;-)
// ALSO - note that latest.img must be public write and in a
// live appliaction should be in another (safe!) directory.
move_uploaded_file($_FILES['upload']['tmp_name'],"latest.img");
$instr = fopen("latest.img","rb");
$image = addslashes(fread($instr,filesize("latest.img")));
if (strlen($instr) < 149000) {
mysql_query ("insert into pix13(name,email,city,state,zip,country,month,date ,upload) values ('\"". $_POST[name] . "\",\"".$_POST[email]. "\",\"".$_POST[city]. "\",\"".$_POST[state]. "\",\"".$_POST[zip]. "\",\"".$_POST[country]. "\",\"".$_POST[month]. "\",\"".$_POST[date]. "\",\"". $_POST[whatsit] . "\", \"". $image . "\")");
} else {
$errmsg = "Too large!";
}
}
$gotten = @mysql_query("select * from pix order by pid desc limit 1");
if ($row = @mysql_fetch_assoc($gotten)) {
$name = htmlspecialchars($row[name]);
$email = htmlspecialchars($row[email]);
$city = htmlspecialchars($row[city]);
$state = htmlspecialchars($row[state]);
$zip = htmlspecialchars($row[zip]);
$country = htmlspecialchars($row[country]);
$month = htmlspecialchars($row[month]);
$date = htmlspecialchars($row[date]);
$bytes = $row[upload];
} else {
$errmsg = "There is no image in the database yet";
// Put up a picture of our training centre
$instr = fopen("latest.img","rb");
$bytes = fread($instr,filesize("latest.img"));
}
// If this is the image request, send out the image

if ($_POST[gim] == 1) {
header("Content-type: image/jpeg/jpg/zip");
print $bytes;
exit ();
}

?>[/php]

Before you continue: Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that. - moderator
Mar 3 '08 #1
3 2071
bonski
53
The below code can't take the images.plz tell that what is the problem in that code
what exactly you want to do? upload image file and display it on a webpage?
Mar 3 '08 #2
bonski
53
ok... i checked your script... for me.. i think you sql statement is having some errors or cant successfully insert the data.. because you lack some single quotes in your $_POST[]...

i think this one
[PHP]mysql_query ("insert into pix13(name,email,city,state,zip,country,month,date ,upload) values ('\"". $_POST[name] . "\",\"".$_POST[email]. "\",\"".$_POST[city]. "\",\"".$_POST[state]. "\",\"".$_POST[zip]. "\",\"".$_POST[country]. "\",\"".$_POST[month]. "\",\"".$_POST[date]. "\",\"". $_POST[whatsit] . "\", \"". $image . "\")");[/PHP]


should look like this

[PHP]mysql_query ("INSERT INTO pix13(name, email, city, state, zip, country, month, date, upload) VALUES('".$_POST['name']."', '".$_POST['email']."', '".$_POST['city']."', '".$_POST['state']."', '".$_POST['zip']."', '".$_POST['country']."', '".$_POST['month']."', '".$_POST['date']."', '".$_POST['whatsit']."', '".$image."')");[/PHP]

and for uploading files, you can have a look at this
file uploads
Mar 3 '08 #3
ronverdonk
4,258 Expert 4TB
The below code can't take the images.plz tell that what is the problem in that code
That is not a clear description of your problem. Please describe it in more detail and let's not make a puzzle of it.

Ronald
Mar 3 '08 #4

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

Similar topics

2
by: Patrick F | last post by:
Hi, i have a resourcefile with my project that contains a jepg image. Now i want to retrive that image to a Image m_Image in my program. Whats the best way to do this?
0
by: chpatel | last post by:
hello, I have serious problem. that must be solved as quickly as possible. I store image (gif, bmp, jpeg) in access database as OLEOBJECT.. Now i want to retrive that image(stored in access)...
8
by: hemashiki | last post by:
hi i need help..how can i store image in mysql database and i want to retrive that image can anyone suggest plz
2
by: soma.gunasekaran | last post by:
Hi All , I've stored the Image file..... But i want to retriving the Image files from MSACCSS 2003 (JPEG,bmp,Gif and etc....) So Pls help me........ help me............... Thanking you,...
1
by: =?Utf-8?B?SHVzYW0=?= | last post by:
Hi EveryBody: I have the following code that I used in my application to retive image from database: Dim cnn As New SqlConnection("Data Source=localhost;Initial Catalog=Husam;Integrated...
1
by: amritranjan | last post by:
How to retrive image file from MS access database and display this in another JSPpage -------------------------------------------------------------------------------- This is my Jsp code for...
2
by: keerthisreenu | last post by:
hai to all...!! iam working with Ms Access 2000. iam saving an image in the database. After that i want to retrive the same image from database and displaying it in the picture box. but its not...
2
by: Eminosoft | last post by:
I am new to the php. plz tell that code for "how to store image in mysql database and also retrive that image"
0
by: ramuygl | last post by:
want to create store procedure that. want to send the table name as argument and retrive the data of that argument. and want to store data in temperary table using the insert query. HERE I AM...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.