Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

php image retrieving

images

  • Please log in to reply
3 replies to this topic

#1 monmohnish

monmohnish

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts
  • Programming Language:C
  • Learning:C

Posted 07 August 2012 - 11:35 PM

Hi all,i have uploaded images in database using php but unable to retrieve it.Plz help me.Am attaching the code for uploading and retrieving images ..plzz check and correct my mistakes.......
you can even mail me to mohnish34@gmail.com

Thanks in advance.

Attached Files


  • 0

#2 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 08 August 2012 - 12:46 AM

what's your error/problem?
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#3 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 08 August 2012 - 01:49 AM

I would do this:
This handles both POST and GET, and the case of non-existing ID

if (isset($_POST['id']) || $_POST['id'] != "") {
  $id = mysql_real_string_escape($_POST['id']);
} else if (isset($_GET['id']) || $_GET['id'] != "") {
  $id = mysql_real_string_escape($_GET['id']);
} else {
  die("ID is missing");
}
  $query = mysql_query("SELECT * FROM tbl_images WHERE id='".$id."'");
  if (mysql_num_rows($query) > 0) {
  $row = mysql_fetch_array($query);
  $content = $row['image'];
  header('Content-type: image/jpg');
  echo $content;
} else {
  die ("Cannot find ID");
}

  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#4 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 09 August 2012 - 04:52 AM

mysql_real_string_escape should of course be mysql_real_escape_string
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.






Also tagged with one or more of these keywords: images

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download