Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Php: Uploading And Dowloading Images From A Db


  • Please log in to reply
12 replies to this topic

#1 DeliberatelySqueek

DeliberatelySqueek

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:05:58 AM

Posted 12 April 2007 - 02:22 AM

I have been creating a website (http://www.yousellitfree.com) for a business man. The site requires a section where the user can upload pictures of the item they wish to sell. Then in the buy section I need the pictures to appear, first as thumbnails and then at a larger size.

I have a feeling that there is something wrong with by table, because i have a table that allows me to up and down load. unfortunatly that is not the table i am using for this tasks.

How you could help me: explain how to upload and download gifs using PHP, HTML and MySQL database.

BC AdBot (Login to Remove)

 


#2 TehWabbit

TehWabbit

  • Members
  • 7 posts
  • OFFLINE
  •  
  • Local time:08:28 PM

Posted 12 April 2007 - 06:42 AM

I assume you have a form that has a "browse" button (the typical upload text box)? if not, place one in the form. (seel below)

i can give you the code for the SQL but i presume (as your building the site) that you could probably implement what i say.

First of all the form:
use something simple like:

<form enctype="multipart/form-data" action="WHEREVER.PHP" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" /><!--edit that default 100kb-->
Picture <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload my image" />
</form>

thats from a source i used at http://www.tizag.com/phpT/fileupload.php , the rest of the PHP code can be found there, its REALLY easy to implement :flowers:

Say your databaseTable was called "Item" and within that you have several fields such as price etc etc, here make sure you have a field called "PictureURL" or something simular.

From here you can use both those codes together and have it so the value in "pictureURL" is defaultdir/<uploaded file>.gif where <uploaded file> is the value in the user submitted form. (location of the image)


Sorry if its not too clear, that site might be able to help you a bit more than i can, im not very good at explaining things :thumbsup:

#3 Walkman

Walkman

  • Banned
  • 1,327 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:02:28 PM

Posted 12 April 2007 - 07:06 AM

All you need to do is just upload your images using any ftp program to the server/folder you want them to go in.

If you set the images to be called from the database, then all you just need to do is just transfer the images to the folder. That's all you need to do.

To download an image, you can just right-click on it and select Save As.

In case you're confused, your images will not be in a database, they will be in a folder on the site, but the database can make a reference (call) the images from anywhere. The images can also be on another server somewhere else.

Post back if you still have any questions or concerns.

#4 DeliberatelySqueek

DeliberatelySqueek
  • Topic Starter

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:05:58 AM

Posted 12 April 2007 - 09:38 PM

Thanks TehWabbit. :thumbsup:
Checking out the website you suggested now. :flowers:
Will post how it goes.
Thanks again. :trumpet:

#5 DeliberatelySqueek

DeliberatelySqueek
  • Topic Starter

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:05:58 AM

Posted 12 April 2007 - 10:12 PM

Ok, I got the code from http://www.tizag.com/phpT/fileupload.php working. This will allow me to upload files into a folder, which is fine as long as a link to that picture canbe stored in the database.

I approached this task assuming:
1. the picture would be saved into the database
2. the record, including the pictures, would be able to be displayed on a different webpage.

Suggestions?

#6 DeliberatelySqueek

DeliberatelySqueek
  • Topic Starter

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:05:58 AM

Posted 12 April 2007 - 10:55 PM

I have a db on a SQL server in America (I'm in Australia). I upload all the files through the control panel.

The difficulty I am actaully having seems to be with successfully saving a picture into the db. i successfull managed it into a practice table, but having problems with the real table. I must have made a mistake i can't see. I though if i could find/see someone's code and use that I would be able to jump this hurdle.

thanks for your help. :thumbsup:

if you're not sure what my problem is, please ask.

#7 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:01:28 PM

Posted 13 April 2007 - 08:25 AM

In image can be saved to a SQL database as a BLOB datatype. Are you responsible for creating the tables in your database, or did someone else create it for you? TehWabbit already gave you the correct info for the form and php part, so if we canfigure out what is wrong with your database, then we can gain some ground.

Do you have the sql script for your practice table? Do you have the script for the 'real' table?

#8 DeliberatelySqueek

DeliberatelySqueek
  • Topic Starter

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:05:58 AM

Posted 13 April 2007 - 05:24 PM

the table can be viewed at this address:
http://www.yousellitfree.com/table.htm

I couldn't find a way to make myPHPadmin show the table in SQL form. if you know how yet me know and i will try it too.

#9 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:01:28 PM

Posted 13 April 2007 - 06:25 PM

Do you have command line access to the database?

#10 DeliberatelySqueek

DeliberatelySqueek
  • Topic Starter

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:05:58 AM

Posted 15 April 2007 - 08:04 PM

I don't think so:
http://www.yousellitfree.com/table.htm

#11 DeliberatelySqueek

DeliberatelySqueek
  • Topic Starter

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:05:58 AM

Posted 15 April 2007 - 08:06 PM

do you have source code of the upload and download pages from a site that i could look at please? This is another option for me, as hopefully I would be able to troubleshoot my db problem.

#12 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:01:28 PM

Posted 15 April 2007 - 08:23 PM

They probably don't want you to have command line access... makes 'em nervous. :thumbsup:

It appears, though, that the datatype for the images is blobs. Grinler would be the person to help you with the PHP stuff. But as a secondary thought... if you could do it on a practice table, you should be able to do it on the production table also. The usual holdup is permissions. And since nobody asked you about errors, are you getting any? I should have asked before. I'm sorry.

#13 DeliberatelySqueek

DeliberatelySqueek
  • Topic Starter

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Local time:05:58 AM

Posted 15 April 2007 - 10:21 PM

no errors as such.

i have a piece of code that uploads a picture and shows the last picture uploaded on the same webpage. when i conect this to the practice table it works fine (the picture of the car appears after it has been uploaded). when i connect the same piece of code (same page) to the real table and upload the same picture (the car), the car doesn't appear, all i see instead is the error picture (you know the default one: white square with a red cross inside).

any ideas?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users