Welcome Guest, Not a member yet? Register   Sign In
postgres bytea fields
#1

[eluser]Andy Chapman[/eluser]
Hi all, not sure if I'm doing something wrong but I'm having trouble maintaining file integrity when writing to / reading from postgres bytea fields.

I have a page where a file is uploaded and stored in a postgres byte a field.

When writing the file to the database, I'm using ActiveRecord like so:

Code:
$data = file_get_contents($_FILES["resource_file"]["tmp_name"]);
   if(!$data)
      show_error("Sorry, could't read the uploaded file!");
                
   $update_data["filedata"] = pg_escape_bytea($data);

Then when I'm trying to restore the file, I'm doing this:

Code:
// Output the appropriate header  and content disposition.
    header("Content-type:$m_type");
    header("Content-Disposition:attachment;filename='" . $file_name . "'");

    // Output the file.
    print pg_unescape_bytea($obj_resource->filedata);

The file comes out bigger than it should be and corrupted. I've tried not using the pg_escape_bytea methods but then the file data isn't inserted into the database properly at all.

Any ideas?


Messages In This Thread
postgres bytea fields - by El Forum - 01-06-2009, 11:40 PM
postgres bytea fields - by El Forum - 01-09-2009, 06:49 AM
postgres bytea fields - by El Forum - 01-09-2009, 06:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB