I guys, I want to upload files to a MySQL database in PHP....
The connection is OK...
but there is a problem with the document column..
If anyone can help me , please give me a working solution..

Can anyone please help me...??

Member Avatar for diafol

You want to store the contents or the filepath?

//EDIT

Look, you really need to show some patience - posting a bump after 5 minutes is just rude, a sure fire way to getting yourself ignored.

You want to store the contents or the filepath?

//EDIT

Look, you really need to show some patience - posting a bump after 5 minutes is just rude, a sure fire way to getting yourself ignored.

I want to store a document(CV)
This is my web page interface.

http://img683.imageshack.us/i/upload2k.jpg/

I can add all the other fields to the database , but not CV... :(

The data-type of the field CV is longblob.

How can I store the document in this column...??

Member Avatar for diafol

First of all, you need to grab the file itself and pour the contents into a blob field.

make sure your form has the attributes: method="post" enctype="multipart/form-data"

THen you open the file and grab the contents
I like to use file_get_contents(), but you can use others.
Addslashes should be applied in order to prevent quotes within the document from messing up your SQL query

$content = addslashes(file_get_contents($_FILES['myfile']['tmp_name']));

then pass the $content var to your SQL statement.

First of all, you need to grab the file itself and pour the contents into a blob field.

make sure your form has the attributes: method="post" enctype="multipart/form-data"

THen you open the file and grab the contents
I like to use file_get_contents(), but you can use others.
Addslashes should be applied in order to prevent quotes within the document from messing up your SQL query

$content = addslashes(file_get_contents($_FILES['myfile']['tmp_name']));

then pass the $content var to your SQL statement.

Hi, thanks .....
Its working now...
Now, Im trying to get the file back(download)
If any help needed, I'll get back to u...
Thanks again...

What are the modifications needed to make this file upload success...

Member Avatar for diafol

FOr retrieving the file, you need to extract the data and place it into a file (e.g. file_put_contents). A simple php redirect to the newly created file can serve as a 'download'. Otherwise, depending on the content, you can createthe file with specific type headers (e.g. pdf, images etc).

Personally, I wouldn't bother with storing files in a DB, I'd just keep the filepaths there and store the uploaded file in an uploads directory.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.