Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using PHP / MySql to upload photos

Status
Not open for further replies.

New2Biz

Programmer
Oct 23, 2007
12
US
I am getting a lot of use out of data uploads to MySql databases via PHP, but would like to expand into uploading photos. Can anyone name a good source (book) that would team me how to write code for this? Is it even PHP?

 
Yes, as a matter of fact it is, and if you know how to upload regular files, photos are exactly the same.

However I would not really store the pictures in the database itself, but just the path to the photos that I store on the server.


Google has quite a few suggestions to it:
PHP uploading files

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I know how to use links to show photos, etc. , but how would I go about allowing a user to post photos on my site that may not have the photos anywhere else (on another site). I have added functionality where they place the address for photos into a form and when it shows their dat the photo appears, but I would like to expand from that.
 
store all the photos in a directory that has an .htaccess file denying access from all
Code:
deny from all

store all your images in this directory and give each a unique name. store the unique name in the database together with the path and the image type

when you want to display an image echo an html tag that looks like this

Code:
<img src="imageScript.php?imageID=12312" alt="sometext"/>

then have the imageScript.php do something like this

Code:
$result = mysql_query("Select from images where imageID = " . trim(mysql_escape_string($_GET['imageID'])));
$row = mysql_fetch_assoc($result);
switch ($row['imageType']){
 case 'jpeg': header('Content-Type: image/jpeg');
 //etc
} //end switch
//get the image size
$length = filesize('/path/to/image/'. $row['imageFileName']);
header('Content-Length: ' . $length);
//now send the image
readfile('/path/to/image/'.$row['imageFileName']);
exit(); //kill the script

you can add in controls to this file to output blank images if the requesting user does not have the right permission to access certain images.
 
As jpadie said, just store the uploaded files in a directory.
This has a pretty good step by step:


Once you have uploaded the files, images, then follow jpadie's advice to create the links to the images now stored on your server.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top