Connect with Facebook Lost Password?


Go Back   CodeCall Programming Forum > Software Development > Tutorials > PHP Tutorials

PHP Tutorials PHP Tutorials

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #21 (permalink)  
Old 09-01-2008, 09:38 AM
wendellrt's Avatar   
Newbie
 
Join Date: Sep 2008
Posts: 2
Rep Power: 0
wendellrt is an unknown quantity at this point
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

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???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #22 (permalink)  
Old 09-01-2008, 09:50 AM
wendellrt's Avatar   
Newbie
 
Join Date: Sep 2008
Posts: 2
Rep Power: 0
wendellrt is an unknown quantity at this point
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

You could try putting the following...
Code:
header('Content-type: image/jpg');
before the line which reads...

Code:
echo $content;
HTH.

Last edited by Jaan; 10-13-2008 at 01:36 PM.. Reason: Please use code tags when you're posting your codes!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #23 (permalink)  
Old 09-12-2008, 10:08 AM
Newbie
 
Join Date: Sep 2008
Posts: 1
Rep Power: 0
casper3000ah is an unknown quantity at this point
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

thank you for ur effort

thanks man
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #24 (permalink)  
Old 10-13-2008, 12:45 PM
Newbie
 
Join Date: Oct 2008
Posts: 3
Rep Power: 0
billjones is an unknown quantity at this point
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

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..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #25 (permalink)  
Old 10-13-2008, 12:56 PM
Newbie
 
Join Date: Oct 2008
Posts: 3
Rep Power: 0
billjones is an unknown quantity at this point
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

can anyone help with the above?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #26 (permalink)  
Old 10-13-2008, 01:37 PM
Jaan's Avatar   
Moderator
 
Join Date: Dec 2006
Location: Estonia
Age: 18
Posts: 1,518
Blog Entries: 4
Rep Power: 24
Jaan is just really niceJaan is just really niceJaan is just really niceJaan is just really niceJaan is just really nice
Send a message via MSN to Jaan
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #27 (permalink)  
Old 10-14-2008, 08:24 AM
Newbie
 
Join Date: Oct 2008
Posts: 3
Rep Power: 0
billjones is an unknown quantity at this point
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

Hi Jann,

Thanks for the quick reply, here is my code.

PHP 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($fpfilesize($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>
this works fine untill i try to get the pic out of the db......

php code for print_pic.php

PHP 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>
I hope you can help.

Thanks Bill.

Last edited by Jordan; 11-09-2008 at 08:18 PM.. Reason: added tags
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #28 (permalink)  
Old 11-09-2008, 08:14 PM
orjan's Avatar   
Guru
 
Join Date: Sep 2007
Location: Sunne, Värmland, Sweden
Age: 34
Posts: 1,303
Blog Entries: 7
Rep Power: 18
orjan is just really niceorjan is just really niceorjan is just really niceorjan is just really nice
Send a message via MSN to orjan Send a message via Skype™ to orjan
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #29 (permalink)  
Old 11-19-2008, 03:47 PM
Newbie
 
Join Date: Nov 2008
Posts: 1
Rep Power: 0
anujphp is an unknown quantity at this point
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #30 (permalink)  
Old 11-20-2008, 01:20 PM
Jaan's Avatar   
Moderator
 
Join Date: Dec 2006
Location: Estonia
Age: 18
Posts: 1,518
Blog Entries: 4
Rep Power: 24
Jaan is just really niceJaan is just really niceJaan is just really niceJaan is just really niceJaan is just really nice
Send a message via MSN to Jaan
Default Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

your link must be..

displayimage.php?id=1
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Storing Images in MySQL with PHP Jordan PHP Tutorials 23 06-02-2009 10:01 PM
Tutorial: PHP to MySQL Jordan PHP Tutorials 9 09-05-2008 12:12 PM


All times are GMT -5. The time now is 10:05 PM.

Freelance Jobs

XML/XSL: Need code for Book with Chapers using XML
Create an XML file for a book of your creation, and a basic CSS file that will format it to display ...
Earn: $40.00


C++/C: Simple firework cue sequencer
What I require is a rework of a simple cue sequencer. I have a piece of hardware (an Arduino boar...
Earn: $50.00


HTML/XHTML: Menu Rework - ASCIIBin
I'm placing this in the HTML/XHTML section of the Freelance site but you are not limited to HTML. Wh...
Earn: $20.00



CodeCall Goal

Goal #1: 1,000 Blogs
Goal #2: 1,000 Wiki Pages
Goal #3: 300,000 Posts
Goal #4: 20,000 Threads
Done: 30%, 23%, 55%, 75%

Ads