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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alper Adatoz

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

    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 ?
    i tried this code ;
    $image = $_FILES['form_data']['name'];
    $image_yol = $_FILES['form_data']['tmp_name'];
    $newdata = "$image_yol ";
    $data = addslashes(frea d(fopen($image_ yol, "r"),
    filesize($image _yol)));

    to put image to the db...
    but it gave me an error like
    "'PHP Warning: mssql_query(): message: Line 7: Incorrect syntax near
    'Japanese'. (severity 15) in d:\www\docs\php _viva\functions .php on
    line 3 PHP Warning: mssql_query(): message: The identifier that starts
    with 'vG!§÷kþZJ{®§õ ¢ô¦ÎvUtŸÝ\\\'_ó ~’æòÆçÕz‰›nŽì aú{W‹_‘~M®»\\\ "Ç[cŒ¹î$’~j#nˆÒ-ölñ¿õrÇí¶»éó‹ $Ðs—QÒ¾²ô^®ÙÁÊ e¤rÐ}ÃâÃî_9{U ÜL«°ÞËñ‹'
    is too long. Maximum length is 128. (severity 15) in
    d:\www\docs\php _viva'is too long. Maximum length is 128"



    do you have any idea?


    Thanks,
  • Richard Grove

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

    "Alper Adatoz" <allper@myway.c om> wrote in message
    news:eae08b72.0 311110522.62b12 fd3@posting.goo gle.com...[color=blue]
    > 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 ?
    > i tried this code ;
    > $image = $_FILES['form_data']['name'];
    > $image_yol = $_FILES['form_data']['tmp_name'];
    > $newdata = "$image_yol ";
    > $data = addslashes(frea d(fopen($image_ yol, "r"),
    > filesize($image _yol)));
    >
    > to put image to the db...
    > but it gave me an error like
    > "'PHP Warning: mssql_query(): message: Line 7: Incorrect syntax near
    > 'Japanese'. (severity 15) in d:\www\docs\php _viva\functions .php on
    > line 3 PHP Warning: mssql_query(): message: The identifier that starts
    > with[/color]
    'vG!§÷kþZJ{®§õ ¢ô¦ÎvUtŸÝ\\\'_ó ~’æòÆçÕz‰›nŽì aú
    {W‹_‘~M®»\\\ "Ç[cŒ¹î$’~j#nˆÒ-ölñ¿õrÇí¶»éó& #8249
    ;$Ðs—QÒ¾²ô^®ÙÁ Êe¤rÐ}ÃâÃî_9{ UÜL«°ÞËñ‹'[color=blue]
    > is too long. Maximum length is 128. (severity 15) in
    > d:\www\docs\php _viva'is too long. Maximum length is 128"
    >
    >
    >
    > do you have any idea?
    >
    >
    > Thanks,[/color]



    Why do you want to fill up a database with this sort of stuff?
    Why not just save the file to a directory, it would be much quicker and
    won't slow down an already slow MSSQL server.

    Regards
    Richard Grove


    http://shopbuilder.org - ecommerce systems
    Become a Shop Builder re-seller:
    Affiliate marketing is a simple way to earn money online, using our affiliate platform. Join a global community of publishers and advertisers.

    Affiliate marketing is a simple way to earn money online, using our affiliate platform. Join a global community of publishers and advertisers.



    Comment

    • ChronoFish

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


      "Alper Adatoz" <allper@myway.c om> wrote in message news:eae08b72.0 311110522.62b12 fd3@posting.goo gle.com...[color=blue]
      > 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 ?[/color]


      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.

      [color=blue]
      > i tried this code ;
      > $image = $_FILES['form_data']['name'];
      > $image_yol = $_FILES['form_data']['tmp_name'];
      > $newdata = "$image_yol ";
      > $data = addslashes(frea d(fopen($image_ yol, "r"),
      > filesize($image _yol)));
      >[/color]

      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:



      [color=blue]
      > to put image to the db...
      > but it gave me an error like[/color]
      ....[color=blue]
      > do you have any idea?
      >[/color]


      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:



      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


      Comment

      • Ekkehard Morgenstern

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

        Hi Alper Adatoz,

        "Alper Adatoz" <allper@myway.c om> schrieb im Newsbeitrag
        news:eae08b72.0 311110522.62b12 fd3@posting.goo gle.com...[color=blue]
        > i just want to put jpeg file to the image field at the mssql db.[/color]

        I've done this only with MySQL before, but I figure it could be similar with
        MSSQL.

        1. You can create a BLOB field of the appropriate size in the database
        table.
        2. Then, you can load the image file that has been uploaded by the user
        (like, with file_get_conten ts() ).
        3. Then, you encode the binary data to base64 format using base64_encode() .
        4. Then, you can simply use it in an INSERT or UPDATE SQL command:

        $bindata = file_get_conten ts( $filename );
        $b64data = base64_encode( $bindata );
        $result = mysql_query( "INSERT INTO MYTBL ... SET IMAGE='$b64data '",
        $dblink );

        To retrieve the image stored in the database, simply read the row, access
        the field, base64_decode() it and output it to the user.

        For output to the user, you can use a specific PHP script that reads the
        image from the database, sets the HTTP headers and then outputs the binary
        data.

        See RFC 2616 (HTTP 1.1 specification), available from
        http://www.rfc-editor.org, for information about the HTTP protocol.

        This method has one disadvantage, that if the base64-encoded image data
        would exceed the SQL INSERT/UPDATE command length limit. I haven't tried yet
        if databases like MySQL can use arbitary-sized SQL queries.

        I hope that helps.

        Regards,
        Ekkehard Morgenstern.


        Comment

        • Jedi121

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

          "Alper Adatoz" a écrit le 11/11/2003 :[color=blue]
          > 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 ?[/color]

          Appart from very very specific issues this is to be avoided!
          You would much prefer a directory where you put your files and just the
          filename in the database.
          MySQL is not optimised for this.


          Comment

          • pc_newbie

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

            ChronoFish wrote:
            [color=blue]
            > "Alper Adatoz" <allper@myway.c om> wrote in message news:eae08b72.0 311110522.62b12 fd3@posting.goo gle.com...
            >[color=green]
            >>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 ?[/color]
            >
            >
            >
            > 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.
            >
            >
            >[color=green]
            >>i tried this code ;
            >> $image = $_FILES['form_data']['name'];
            >> $image_yol = $_FILES['form_data']['tmp_name'];
            >> $newdata = "$image_yol ";
            >> $data = addslashes(frea d(fopen($image_ yol, "r"),
            >>filesize($ima ge_yol)));
            >>[/color]
            >
            >
            > 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/functio...oaded-file.php
            >
            >
            >
            >[color=green]
            >>to put image to the db...
            >>but it gave me an error like[/color]
            >
            > ...
            >[color=green]
            >>do you have any idea?
            >>[/color]
            >
            >
            >
            > 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/m...ter/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
            >
            >[/color]

            i am using php and mysql on my localhost

            Comment

            Working...