insert image to a database

Permabanned
Joined
3 May 2008
Posts
69
hello

i have this code which allows a user to browse for an image and inserts the path into the text box

<input type="hidden" name="MAX_FILE_SIZE" value="200" />
<input type="file" name="image" />

it allows a max file size of 200kb

when the rest of the form is complete it inserts everything correctly into the database.

the above filed though appears as "C:\mypics\etc.jpg"

How can I get it so that when the form entry is updated to the db it removes that and either leaves it as etc.jpg or adds images/ to the front of it.

Also, how does that image actually upload and where to?

thanks
 
have you got enctype set on your form like this.....?

Code:
<form action="" method="post" enctype="multipart/form-data">

and storing images in a database isn't a very good idea. you'd be much better off storing them on the server and just referencing their location in the db. :)
 
have you got enctype set on your form like this.....?

Code:
<form action="" method="post" enctype="multipart/form-data">

and storing images in a database isn't a very good idea. you'd be much better off storing them on the server and just referencing their location in the db. :)

ah yeah, thats kinda what I mean. basically, the image path gets stored in the database but the path has the full filename of the users PC. I want it to say images/pic.jpg.

i want the process to be easy for the user thats why i added the browse button.

Is there a way to split this then? have the path enter the db but the image gets uploaded to the images folder?

I'll look through the first link now

thanks
 
I guess what i'm trying to do is as follows.

the user clicks on browse and the file they want gets loaded into the field.

When they click submit, all the form data gets stuck in the database but the image gets uploaded to a temp directory then copied over to the images/ folder.

This images/myimage.jpg gets passed to the db.

I've kinda got it, and I had to CHMOD the directory, but when I upload a image, the extension gets removed. Is this my hosting company doing this with the php.ini?
 
Post your code, another thing you may want to do is renaming the files too, keep the original filename but add a timestamp to it, this will prevent files being over-written.
 
Back
Top Bottom