Forum Moderators: coopster

Message Too Old, No Replies

Uploading files with PHP in Dreamweaver

         

alpha117

2:00 pm on Feb 12, 2005 (gmt 0)

10+ Year Member



Hi Guys
OK, this has probably been asked millions of times, but I cannot seem to find the answer.
I use DW2004 and have just started to use MySQL and PHP.

I can upload files to a directory, that bit is OK.
What I want to do is upload an image and store it in a file (ie /images), then store the the lacation in the Database.
I have set up a DB with a filed called image and type of BLOB, not sure how I get the storage inforamtion into this field.
So how do i store ./images/picture1.jpg in the BLOB filed in the DB, so that it can be retreived and allow the image to display if theuser searches the DB

Many thanks
CLive JOy

Nutter

2:08 pm on Feb 12, 2005 (gmt 0)

10+ Year Member



Are you trying to store the actual image data in the database, or just the path? If it's just the path, which is what I'm guessing, you really don't need to use a blob. You'd be better off with a char / varchar or a text type field if the path is really long.

alpha117

2:54 pm on Feb 12, 2005 (gmt 0)

10+ Year Member



Hi Nutter

Yes I only want to store the image path in the DB

So how do i get this path into the DB field from the input form that he user will fill out after using the 'browse' funtion in on of the form fileds to location the image for upload.
I think I somehow need to capture this variable that takes the source location on the USers PC and stores it in the image folder on the server.
So if it is for example mypicture.jpg that the user uploads and this is stored in ./images/mypicture.jpg on the server, how do i get ./images/mypicture.jpg into the correct db field.

I hope that explains my problem

regards
clive

alpha117

2:55 pm on Feb 12, 2005 (gmt 0)

10+ Year Member



PS..my typing is c...ap to :-)

hakre

3:24 pm on Feb 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi alpha117,

in my opinion you started with the end. first of all, to clear things out, if you're using a form with a file-browse-button on it, the user of the form is not submitting a path to you, she/he is submitting a complete file to your server. detailed information about this is described step by step in the php docs:
Chapter 38. Handling file uploads [de2.php.net]

after that operation, the (image-) file is transfered on the server. you then can work with that file, rename and move it to your wished destination for example. after that, you know for shure where the file is placed so you know the path of that file. this path you can store into your database.

i know there is not one line code in my answer for you, but in my opinion you should get things more clear first so you know how you can solve your problem.

henry0

3:27 pm on Feb 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome on WebMasterWorld Alpha

loading an img in your DB using BLOB is not the best way to do it, with hundreds of img you will load tons of data
better way: Load the image path
varchar should be OK, limit to 250 should be more than enough for the path length

You may often search our library
for ex:
Here is your answer [webmasterworld.com]

(look by end of the thread)
regards

henry

alpha117

3:44 pm on Feb 12, 2005 (gmt 0)

10+ Year Member



Thanks Guys

I am having a look at the link now.

I will come back with more questions, that is for sure.

So briefly then this is what happens:

1. User uploads a file to the server (ie./images/picture1.jpg)

I am still confused on how I get /images/picture1.jpg path into the db field.

Sorry for being thick here, but as you can gather this is new to me.

All I have done so far is to USE PHP via dreamweaver and I have NEVER hand coded anything.

Regards (with headaches!)

clive