Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

- - - - -

Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

mysql

  • This topic is locked This topic is locked
213 replies to this topic

#181 whitestar

whitestar

    CC Regular

  • Just Joined
  • PipPipPip
  • 33 posts

Posted 13 January 2011 - 01:12 AM

Hello there

I know this Thread is 2 years old and not sure if anyone is still available to help me. I am refering to the Tutorial: Storing Images in Mysql with PHP, I cannot reply on that thread as it is closed?

Here is my issue, Im having trouble uploading the image to the DB I have not modyfied the code but on the insert.php page im getting this error

Warning: fopen() [function.fopen]: Filename cannot be empty inC:\xampp\htdocs\the_secrets_out\insert.php on line 295

Warning: fread(): supplied argument is not a valid stream resource inC:\xampp\htdocs\the_secrets_out\insert.php on line 296

Warning: fclose(): supplied argument is not a valid stream resource inC:\xampp\htdocs\the_secrets_out\insert.php on line 298
Thank you, Your file has been uploaded.

refering to this section of the code
// Read the file
|295| $fp = fopen($tmpName, 'r');
|296| $data = fread($fp, filesize($tmpName));
|297| $data = addslashes($data);
|298| fclose($fp);

Im new to PHP and im not sure if this has something to do with the add.html pages code. it seems like when you press submit the information is not being carried to the insert.php page?

Im viewing the pages in IE and using dreamweaver to do the pages if that hepls?

Please help
  • 0

#182 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 13 January 2011 - 02:39 AM

Hey whitestar, $tmpName comes from this code:
   $tmpName  = $_FILES['image']['tmp_name'];  

This means that the file is not being sent from the HTML form, what does your form look like that selects the file?
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#183 whitestar

whitestar

    CC Regular

  • Just Joined
  • PipPipPip
  • 33 posts

Posted 13 January 2011 - 10:47 PM

Thank You ALEXANDER

I actually figured it out just after asking that question. You know how that always happens! But you were one hundred percent right! On one of the lines I had typed tempName instead of tmpName!

Thank you for your speedy response
  • 0

#184 whitestar

whitestar

    CC Regular

  • Just Joined
  • PipPipPip
  • 33 posts

Posted 17 January 2011 - 02:54 AM

Hello All

I hop you can help me.
I am able to add th image to the database using Tutorial: Storing Images in MySQL with PHP & Tutorial: Storing Images in MySQL with PHP / Part II / Display your images .
I have a database"the_secrets_out with a table"subscriber_info" where all the websites subscribers info is stored like first_name, last_name, username, password etc. I have a field called subscriber_id(primary key) and 1 called subscriber_image.

Once people have subscribed to the website I want to allow them to add a profile picture into "subscriber_image". to be added to their record.

I understand that their record needs to be updated with the image being placed in it and this tutorial only adds a new record. How do I change the script to update the record instead of insert a new one?

I am new to php and am using dreamweaver if that helps.

Your assistance is greatly appreciated
  • 0

#185 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 17 January 2011 - 03:01 AM

Hey whitestar, you best create a new thread in our PHP forum: PHP Forum You may get more help there. Be sure to link to threads you are referencing to as well.
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#186 whitestar

whitestar

    CC Regular

  • Just Joined
  • PipPipPip
  • 33 posts

Posted 17 January 2011 - 03:44 AM

Thanks Alaxander
I did so(Need help updating a mysql record by adding an image with php) I did link it to the tutorials I was referencing but had trouble adding the code tags. I kept getting an error that the website is doing maintenance or there is a programming error!
  • 0

#187 opdan1st

opdan1st

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 17 January 2011 - 10:11 AM

hi jaan
when i run the code you wrote, to select (for example image number two) it returns

http://localhost/ret...eimage.php?id=2

on the browser window, i dont see any image.

please help
  • 0

#188 bakhtn

bakhtn

    CC Lurker

  • Just Joined
  • Pip
  • 8 posts

Posted 17 January 2011 - 03:01 PM

nice pic of birdman you got there
  • 0

#189 wizardzaw

wizardzaw

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 18 January 2011 - 01:49 AM

I have a problem using that code in my program. What I would like to do is I have a number of PDF map document on my home page and when user hover over mouse on the link it shows the thumbnails images (.
I have created database for that part as well as PHP pages. When i embedded the code to my php Page it show the correct number of images from database. However on the popup it only show binary codes instead of showing the images.

Please kindly advice on this issue.
Highly appreciate for your kind help.

Wynn.
  • 0

#190 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 18 January 2011 - 04:31 AM

Hey wizardzaw, you will need to call the header() function as seen in the tutorial, to display those binary as an image.
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#191 kirigwajoe

kirigwajoe

    CC Lurker

  • Just Joined
  • Pip
  • 9 posts

Posted 26 January 2011 - 09:04 AM

it is not displaying the image.

" Please select your image!" is what is displayed in the browser.

here is my code.
<?php 
$username = "root";
$password = "";
$host = "localhost";
$database = "child";

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());

$pid = $_GET['pid'];

if(!isset($pid) || empty($pid) || !is_int($pid)){
die("Please select your image!");
}else{

$query = mysql_query("SELECT * FROM jpg WHERE pid='".$pid."'");
$row = mysql_fetch_array($query);
$content = $row['image'];

header('Content-type: image/jpg');
echo $content;
}

?>


where do i specify the image number from.

i have entries from 1 to 30 in my database.

please help.
  • 0

#192 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 26 January 2011 - 10:43 AM

You specify the number in your URL.
http://localhost/image.php?pid=4
  • 0





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