Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Loading and saving an image to the database
  • Hi there,

    how would I save an image to the database with FuelPHP? I don't want to do the hassle of creating my own storing system on the server, but instead using a blob.
    I know how to do on my own in PHP. But I guess that you folks have implemented a rather easy way to do it.

    Any help would be much appreciated, or hint, or direction.
  • Isn't that a value as any other? The DB layer doesn't care what you want to save...
  • Well yes, I expected so. But as I am still at my early days or years in using PHP I was filing in the src-tag by giving it the data. Which doesn't work here.

    Html::img($image->data);

    is what I'm using.

    I am saving the data by using the (rather complicated way and somehow wrong way):

    $iData = $_FILES['data']['tmp_name'];
    $ih = fopen($iData, 'r');
    $data = addslashes(fread($ih, filesize($iData)));
    fclose($ih);

    $image = Model_Image::forge(array(
                        ...
                        'data' => $data,
                        ));

  • HarroHarro
    Accepted Answer
    If this is about uploading files, have you checked out the Upload class? And the Image class for loading and manipulating image files?
  • Yes... it was late for me and I forgot how to write (and google). Never mind. I'll ask later if I have any more questions.

    But thanks.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion