0
votes

I'm receiving a zip file which I need to save to a database. However it seems to be saved incompletely.

In this function:

public function executeUploadFile(sfWebRequest $request){

    if (!$_FILES['file']['error']){
        $fn = $_FILES['file']['tmp_name'];
        $fh = fopen($fn,'r+');
        $fc = fread($fh, filesize($fn));
        mail('[email protected]','test 3',$fn.'-'.filesize($fn).'-'.strlen($fc));
        fclose($fh);
        move_uploaded_file($_FILES['file']['tmp_name'],dirname(__FILE__).'/'.$_FILES['file']['name']);
        $q = Doctrine_Query::create()
            ->update('PrimhdLog')
            ->set('results', "'".mysql_escape_string($fc)."'")
            ->where("files_expected like '%".$_FILES['file']['name']."%'");
        $sql = $q->getSqlQuery();
        print $sql;
        $uprows = $q->execute();
    }else{
        mail('[email protected]','uploadFile has error on file',print_r($_FILES,1));
    }

    return sfView::NONE;
}

I have files uploaded with sizes (bytes) 4028,1658,2777 respectively. The email log and "ls -la" confirms these sizes.

However SELECT char_length(results), length(results), primhd_log.* FROM primhd_log WHERE 1 shows sizes 3900, 1607, 2692 respectively.

Any idea how to identify this problem?

Version is Symfony 1.4.6

Schema:

PrimhdLog: actAs: Timestampable: created: name: created type: timestamp columns: id: { type: integer(4), notnull: true, unique: true, primary: true, autoincrement: true } created_by: { type: integer(4) } details: { type: clob(16000000), notnull: true } submitted: { type: timestamp } submitted_by: { type: integer(4) } results: { type: clob(16000000) } start: { type: timestamp } end: { type: timestamp } files_expected: { type: clob(16000000) } output_filename: { type: string(100) } relations: Creator: { class: Person, local: created_by, foreignAlias: CreatorPRIMHDLogList } Submitter: { class: Person, local: submitted_by, foreignAlias: SubmitterPRIMHDLogList }}

1

1 Answers

0
votes

What is your schema? What is the data type you are saving the info into? 'text'? 'blob'?

A zip file contains many special chars that even mysql_escape_string won't catch, if it's some crazy ^@ or ^M, that is just being skipped it would account for the size difference.

Not much help but an idea