Page 1 of 1

Image upload database reference - image name row ID

Posted: Wed Feb 16, 2005 7:01 pm
by Jim_cliff11
Hi all,

I have the following table structure:-

Code: Select all

CREATE TABLE `sales` (
`SaleID` int(5) NOT NULL auto_increment,
`Title` varchar(255) NOT NULL default '',
`Image_Ref` varchar(255) NOT NULL default '',
`Description` text NOT NULL,
`Date` date NOT NULL default '0000-00-00',
PRIMARY KEY (`SaleID`),
FULLTEXT KEY `Description` (`Description`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
I want to have a form in which i can fill in the fields for the database table above. And also select a picture to upload to a directory and automaticlly add a reference to the table (ive been told this is better than storing the image inside the table itself). I want it so when the image is uploaded to the directory the image reference is added to the database and the image name is changed to the specific row ID of the table.

How would i do this, can anyone help me because im stuck?

Thanks alot

Jim


feyd | please use formatting tags when posting code

Posted: Wed Feb 16, 2005 7:08 pm
by feyd
stuck where? you listed a lot of stuff.

what do you have already?

Posted: Wed Feb 16, 2005 7:23 pm
by Jim_cliff11
Basiclly i have made the table structure (table name = sales) above and made the table in the mysql database (db name = gbplat).

Now im stuck on howto have an upload page that uploads an image into a directory on the server and adds a reference to the database for the image thats just been uploaded, so that the image dosnt have to be stored inside the database as binary data. Also i dont know howto make the image name change to the specific row ID when its uploaded. For example, SaleID 5, i would like the image name auto changed to
SaleImage-5, SaleID 6 i would like the image name changed to
SaleImage-6 and so on. And at the same time add a reference to the database table field Image_Ref to link to the uploaded image.

How would i go about doing this.
Im fairly new to databases, so any help would be greatly appriciated.

Thanks
Jim

Posted: Wed Feb 16, 2005 8:27 pm
by feyd
there have been a lot of threads here on file upload handling, this may help too.

as for renaming the file, during the call to move_uploaded_file() you can rename it to whatever you wish. To retrieve the id used for the user row, last_insert_id() can return that.



You may want to consider increasing the size of the SaleID field.