Help - Search - Members - Calendar
Full Version: how to upload an image or file to mysql?
HTMLHelp Forums > Programming > Databases
mzminnie
Hi,

I'm new to this forum and to making websites. I just started one but I'm having trouble uploading an image or file. I'm trying to create a website where I can upload jpegs and it will store it on mysql. On a different page, it will retrieve the pictures from the table and display it.

Thanks for the help.
Brian Chandler
In general you do not store image files inside the database; just store the filename.

(If you are really just starting "making websites" and have no programming experience you will not find it easy to write a file uploading and indexing system!)
mzminnie
I understand that that you store just the filename and move image to a folder. But the image is not going in the folder. I tried to look up how to do it but it's still not working.
The events folder is in the same directory as the source files.

This is what I have:

move_uploaded_file($_FILES["flyer"]["tmp_name"],"/events/" . $_FILES["flyer"]["tmp_name"]);

Thanks
Brian Chandler
QUOTE(mzminnie @ Oct 7 2009, 07:27 AM) *

I understand that that you store just the filename and move image to a folder. But the image is not going in the folder. I tried to look up how to do it but it's still not working.
The events folder is in the same directory as the source files.

This is what I have:

move_uploaded_file($_FILES["flyer"]["tmp_name"],"/events/" . $_FILES["flyer"]["tmp_name"]);

Thanks


First thing to do is to change it to

CODE

$from = $_FILES['flyer']['tmp_name'];
$to = '/events/' . $_FILES['flyer']['tmp_name'];
echo "<br>Copy $from ==) $to \n";
move_uploaded_file($from, $to);


Then you can see what's happening.

Anyway, you seem to be copying the file to /events/something, so unless the top-level directory /events/ exists, it won't work. Perhaps you mean 'events/something'... ?

Incidentally, the manual explicitly says that if the file exists it will be overwritten, and since the filename is given by the user, this means if user1 uploads a useful file called penguin.jpg, it will be lost if user2 happens to upload a piece of junk called penguin.jpg. So I think you want to save the given title in the database, perhaps, but assign a new filename on the database key.

mzminnie
Thanks, I got it working.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.