iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-04-2005, 11:47 AM
WebProWorld Pro
 
Join Date: Jan 2004
Location: Milton Keynes, UK
Posts: 115
DarrenPWS RepRank 0
Default PHP MySQL Image Upload

Hi all,

I have a couple of things I need to be able to do.

I am building a site that sells scanners.

It will be a database-driven site, and so I want to be able to add new products etc. through the web interface.

I have created an admin section where I will be able to do just this - but I do not know how to upload an image to a directory, and insert the location into a mysql field, called image for example.

There is more to it than this - It would be great if on uploading the image, the image is inserted into the folder (i.e. /img/scanners/) - and into the database (i.e. scanners.image) - and then the image is resized to 100px in width, and then that image is inserted into the folder (i.e. /img/thumbs/) and then into the database (scanners.thumbnails).

I really dont think I can explain in much more detail - but all help / suggestions are greatly appreciated.

Thanks for reading my huge request.

D.
Reply With Quote
  #2 (permalink)  
Old 03-04-2005, 12:04 PM
WebProWorld Pro
 
Join Date: Feb 2005
Location: New York
Posts: 141
roban RepRank 0
Default

What are you using for your site? PHPWebsite? If so Photo Album will do much of that. Do you have access to PHPMyAdmin through your host?
Reply With Quote
  #3 (permalink)  
Old 03-04-2005, 12:24 PM
WebProWorld Veteran
 
Join Date: Nov 2003
Location: Castle Rock, CO
Posts: 494
Corey Bryant RepRank 0
Default

What shopping cart are you using? Most would actually do this already it would seem?
Reply With Quote
  #4 (permalink)  
Old 03-04-2005, 12:30 PM
WebProWorld Pro
 
Join Date: Jan 2004
Location: Milton Keynes, UK
Posts: 115
DarrenPWS RepRank 0
Default

I am writing my own shopping cart for it, and so everything is to be done from scratch.

I do have access to PHPMyAdmin.

Thanks.
Reply With Quote
  #5 (permalink)  
Old 03-04-2005, 12:42 PM
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Cornwall, UK
Posts: 972
speed RepRank 1
Default

PHP:

$file = $_FILES['filePic'];
move_uploaded_file($file['tmp_name'], $fileName);

HTML:
<form id="upload" action="test.php" method="post" name="upload" enctype="multipart/form-data">
<input type="file" name="filePic" size="40" />
</form>

In the PHP you need to set $fileName to the name of the file you want the image stored as, you can also store $fileName in the database.

If you want to resize/check the image format being uploaded then look up the following in the PHP manual:
getimagesize
ImageCreateFromJPEG
ImageJPEG
ImageCopyResampled

There are other commands but those should get you started :)
Reply With Quote
  #6 (permalink)  
Old 03-04-2005, 01:08 PM
WebProWorld Pro
 
Join Date: Jan 2004
Location: Milton Keynes, UK
Posts: 115
DarrenPWS RepRank 0
Default

Thanks for the help - I will have a go with that code, and look at the suggested php manual functinos.

Thanks,

D.
Reply With Quote
  #7 (permalink)  
Old 03-04-2005, 02:40 PM
WebProWorld Pro
 
Join Date: Feb 2005
Location: New York
Posts: 141
roban RepRank 0
Default

I use Cube Cart here and I think it would do what you want.
Reply With Quote
  #8 (permalink)  
Old 03-04-2005, 06:18 PM
WebProWorld Veteran
 
Join Date: Nov 2003
Location: Castle Rock, CO
Posts: 494
Corey Bryant RepRank 0
Default

Sorry Darren, I missed that part. :) - take a look at this code from Dave (sonicgroup) - it might help you out as well.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
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



All times are GMT -4. The time now is 09:15 AM.



Search Engine Optimization by vBSEO 3.3.0