Hello Everyone.
When I use the example code, all I get is a blank (all white) page being displayed in my browser ('view source' displays a blank page as well).
Where did I go wrong???
Hello Everyone.
When I use the example code, all I get is a blank (all white) page being displayed in my browser ('view source' displays a blank page as well).
Where did I go wrong???
You could try putting the following...
before the line which reads...Code:header('Content-type: image/jpg');
HTH.Code:echo $content;
Last edited by Jaan; 10-13-2008 at 01:36 PM. Reason: Please use code tags when you're posting your codes!
thank you for ur effort
thanks man
Hi , Jaan
Can you help a newbie ?
I can upload images into the database with no problems, but retrieving them is a problem, they come out of the database in a raw form, its as if the following code is not working !
header('Content-type:image/jpg');
it does not seem to have an effect, if I delete this part of the code I get the same result! Raw data. Can you help?
Last edited by billjones; 10-13-2008 at 01:10 PM.
can anyone help with the above?
Umm.. do you use the same script or you have changed it..?
If you have changed it, please post it here so I can check what's the problem
█ Trill Hosting - Cheap SSL, Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
█ www.trillhosting.com | support@trillhosting.com
█ Hosting Plans | Write To Us | Support | Client Area | About Us
CodeCall Blog | CodeCall Wiki
Hi Jann,
Thanks for the quick reply, here is my code.
this works fine untill i try to get the pic out of the db......Code:<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>add pic</title>
</head>
<body>
<form action="insert.php" method="post" enctype="multipart/form-data" name="changer" >
<input name1="MAX_FILE_SIZE" value="102400" type="hidden">
<input name="image" accept="image/jpg" type="file">
<input value="Submit" type="submit">
</form>
</body>
</html>
php code for the page insert.php
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>insert</title>
</head>
<?php
// Create MySQL login values and
// set them to your login information.
$username = "abc";
$password = "123";
$host = "localhost";
$database = "test";
// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// Select your database
mysql_select_db ($database);
// Make sure the user actually
// selected and uploaded a file
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
// Temporary file name stored on the server
$tmpName = $_FILES['image']['tmp_name'];
// Read the file
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
// Create the query and insert
// into our database.
$query = "INSERT INTO tbl_images ";
$query .= "(image) VALUES ('$data')";
$results = mysql_query($query, $link);
// Print results
print "Thank you, your file has been uploaded.";
}
else {
print "No image selected/uploaded";
}
// Close our MySQL Link
mysql_close($link);
?>
<body>
</body>
</html>
php code for print_pic.php
I hope you can help.Code:<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
$username = "abc";
$password = "123";
$host = "localhost";
$database = "test";
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
//$id = $_GET['id'];
$id = 1; // just a test id to see if it works!
if(!isset($id) || empty($id)){
die("Please select your image!");
}else{
$query = mysql_query("SELECT * FROM tbl_images WHERE id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['image'];
header('Content-type: image/jpg');
echo $content;
}
?>
</body>
</html>
Thanks Bill.
Last edited by Jordan; 11-09-2008 at 08:18 PM. Reason: added tags
please use the php tags.
this is a special php file when you output the picture, it may not contain any html as it's a picture you're returning, not a web page.
remove everything before <?php and after ?> and it will work. make extremely sure that there are absolutely no letters, spaces or any other symbols before the <?php otherwise, the system might believe it's a web page and goes nuts.
hello
thanks for the code its works fine for me but i have a problem..though the script work fine when i open my page in flock or mozilla or any toher browser but it dont work when i open the page in internet explorer..it try to download the php file....can you kindly solve my this problem....
i am trying to open the file with this url
localhost/test/displayimage.php=?1
IT works fine with in flock and mozilla
your link must be..
displayimage.php?id=1
█ Trill Hosting - Cheap SSL, Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
█ www.trillhosting.com | support@trillhosting.com
█ Hosting Plans | Write To Us | Support | Client Area | About Us
CodeCall Blog | CodeCall Wiki
There are currently 3 users browsing this thread. (0 members and 3 guests)
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum