How to read and write file and store the contents of uploaded file in mysql...

  • Thread starter Thread starter Jimmy
  • Start date Start date
J

Jimmy

Guest
...database using php? I am uploading 1 file I want that file contaent should be stored in my sql database. Means when I upload a file I want read the contents of that files and write that contents of file and stores that contents into database
Please tell me the code if anybody knows?...
 
I couldn't honestly give you the code from memory but I can give you the theory on how to make it work. This is what I used myself when I was working on a similar project.

First use a file upload script. Google for them, there are loads. They're effectively the same thing though. The next thing to do is to tell the file upload script where to save the file. You save that in a Variable.
Then connect to a database and store the file name in whatever field you want.

After that, all you have left to do is to call the image. You connect to the database, set the ID of the row you want to read and then call the file name from that row. Save that filename to a variable, such as $filename.
Embedding the image depends on where you saved the uploaded image. For this example, the image is stored in the "yoursite.com/images" folder.
Create a new variable such as $filepath. Then fill it with "yoursite.com/images/" + $filename.
So if you have an image called mypic1.jpg, $filepath will now contain yoursite.com/images/mypic1.jpg.
Then use the normal <img> tags and set the source as $filepath.

Hope that helps.
 
Back
Top