Re: How can i put the image file to the db ? (mssql)

From: ChronoFish (deja_at_chronofish.com)
Date: 11/11/03


Date: Tue, 11 Nov 2003 09:25:33 -0500


"Alper Adatoz" <allper@myway.com> wrote in message news:eae08b72.0311110522.62b12fd3@posting.google.com...
> Hi,
>
> i have a little problem. i hope u guys give me a clear solution (:
>
> db: mssql
>
> i just want to put jpeg file to the image field at the mssql db.
>
> and after that i want to call it back..
>
> how can i do this ?

You can do this in PHP/MySQL, but you should develop this in an iterative stepwise fashion so that you understand what is happening.
Your code below has two issues. The first is uploading and saving a file. The second is saving binary date to a MySQL database.

> i tried this code ;
> $image = $_FILES['form_data']['name'];
> $image_yol = $_FILES['form_data']['tmp_name'];
> $newdata = "$image_yol";
> $data = addslashes(fread(fopen($image_yol, "r"),
> filesize($image_yol)));
>

With out getting too deep here, your first goal is to be able to upload and save a file - any file - graphic or otherwise. Here's a
hint. You are not going to be "addslashes" to the raw data - only to the data coming from the HTML form.

The PHP documentation is excellent and you will probably find some code you can copy and past from here:
http://www.php.net/manual/en/function.move-uploaded-file.php

> to put image to the db...
> but it gave me an error like
...
> do you have any idea?
>

The next step is saving data to the database. I assume you can save and retrieve text data from the database already. If not,
start there. Once you do that read up on "Blob" data types. The MySQL documentation is not laid out as well as PHP.net (in fact
PHP.net should be the model for document presentation... I digress...) but have fun searching for the information here:
http://www.mysql.com/documentation/mysql/bychapter/index.html

Now you can combine what you've learned and you will have your answer.

But as pointed out in another one of your responses, you may be better off saving the graphic to an "images" directory and then
simply saving the URL to the image in your database.

This would be easier on the database and will be easier to retrieve (you won't have to worry about sending HTTP header info when you
want to display the image from the database), but your requirements may not allow you to be this flexible (i.e. copywrite issues
won't allow a static URL to an image).

Hope this helps,

CF



Relevant Pages

  • WSS Error - IIS application pool user name is invalid
    ... I have deployed a Widows sharepoint server on WMSDE and ... followed the documentation to migrate it to a MSSQL ... trying to connect to the restored configuration Database i ...
    (microsoft.public.sharepoint.portalserver)
  • DBConvert for Access & MSSQL 2.0.0
    ... DBConvert for Access & MSSQL is a database migration tool for data ... If a direct access to your MSSQL server is denied (insufficient ... privileges) you can save your data into a MSSQL Dump file to overcome ...
    (comp.software.shareware.announce)
  • Access2MSSQL PRO 1.2.0
    ... Access2MSSQL Pro is a database migration tool for data conversion from ... MS Access database to MS SQL Server and from MSSQL to ... privileges) you can save your data into a MSSQL Dump file to overcome ...
    (comp.software.shareware.announce)
  • Re: Comments in SQL?
    ... you should have actual DOCUMENTATION that lays out the table design ... design errors, which there will also undoubtably be, and also to promote ... sort through or understand all of the tables of the website. ... The database aspects are ...
    (alt.php)
  • Re: Force a limit to number of rows
    ... I'm no Access interface expert, so I ask myself, ... But what if someone else needs to rebuild the database at some stage? ... application relies on this type of cascade. ... Create a table purely for documentation. ...
    (microsoft.public.access.tablesdbdesign)