I believe the same, but I think Asbjørn made it clear on the blog post
he linked why he was storing files on the DB.

Asbjørn, I see on your code that you have:

// app/controllers/files_controller.php
class FilesController extends AppController
{
    function add()
    {
        if (!empty($this->params['form']) &&

is_uploaded_file($this->params['form']['File']['tmp_name']))
        {
            $fileData =
fread(fopen($this->params['form']['File']['tmp_name'], "r"),

$this->params['form']['File']['size']);
            $this->params['form']['File']['data'] = $fileData;

            $this->File->save($this->params['form']['File']);

            $this->redirect('somecontroller/someaction');
        }
    }
}

Now, why don't you try first BASE 64 encoding the contents of the file?
Eventhough you would be requiring far more storage capacity for each
file, I just want to check that there's no issue with Cake retrieving
BLOB fields. Change the following line:

$this->params['form']['File']['data'] = $fileData;

to:

$this->params['form']['File']['data'] = base64_encode($fileData);

Then, on your code where you download the file, that is:

function download($id)
{
    $file = $this->File->findById($id);

    header('Content-type: ' . $file['File']['type']);
    header('Content-length: ' . $file['File']['size']);
    header('Content-Disposition: attachment;
filename='.$file['File']['name']);
    echo $file['File']['data'];

    exit();
}

Change the line:

echo $file['File']['data'];

to:

echo base64_decode($file['File']['data']);

Try to see if it works. If so, then there's definitely an issue with
binary data on Cake and we can debug further.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to