0

I want to upload zip file in symfony but failed to do so.

When i am uploading text ot pdf or excel file,image or single file then it is uploaded fine.

But when i tried to upload zip file it returns nothig and also there is no error log only blank page is appaear.

Im My form i have the following code.

class UploadSalaryForm extends BaseForm {

    public function configure() {

        // Note: Widget names were kept from old non-symfony version
        $var = 'salary';
        $this->setWidgets(array(
            'EmpID' => new sfWidgetFormInputHidden(),
            'seqNO' => new sfWidgetFormInputHidden(),
            'MAX_FILE_SIZE' => new sfWidgetFormInputHidden(),
            'ufile' => new sfWidgetFormInputFile(),
            'txtAttDesc' => new sfWidgetFormInputText(),
            'screen' => new sfWidgetFormInputHidden(),
            'commentOnly' => new sfWidgetFormInputHidden(),

        ));



        $this->setValidators(array(
            'EmpID' => new sfValidatorNumber(array('required' => true, 'min'=> 0)),
            'seqNO' => new sfValidatorNumber(array('required' => false, 'min'=> 0)),
            'MAX_FILE_SIZE' => new sfValidatorNumber(array('required' => true)),
            'ufile' => new sfValidatorFile(array('required' => false)),
            //'ufile', new sfValidatorFileZip(array('required' => false)),
            'txtAttDesc' => new sfValidatorString(array('required' => false)),            
            'screen' => new sfValidatorString(array('required' => true,'max_length' => 50)),
            'commentOnly' => new sfValidatorString(array('required' => false)),
        ));

        // set up your post validator method
        $this->validatorSchema->setPostValidator(
          new sfValidatorCallback(array(
            'callback' => array($this, 'postValidate')
          ))
        );
    }

    public function postValidate($validator, $values) {

        // If seqNo given, ufile should not be given.
        // If seqNo not given and commentsonly was clicked, ufile should be given
        $attachId = $values['seqNO'];
        $file = $values['ufile'];
        $commentOnly = $this->getValue('commentOnly') == "1";        

        if (empty($attachId) && empty($file)) {
            $message = sfContext::getInstance()->getI18N()->__('Upload file missing');
            $error = new sfValidatorError($validator, $message);
            throw new sfValidatorErrorSchema($validator, array('' => $error));
        } else if (!empty($attachId) && $commentOnly && !empty($file)) {
            $message = sfContext::getInstance()->getI18N()->__('Invalid input');
            $error = new sfValidatorError($validator, $message);
            throw new sfValidatorErrorSchema($validator, array('' => $error));
        }

        return $values;
    }

    /**
     * Save employee contract
     */
    public function save() {

        $empNumber = $this->getValue('EmpID');
        $attachId = $this->getValue('seqNO');

        $empAttachment = false;

        if (empty($attachId)) {
            $q = Doctrine_Query::create()
                    ->select('MAX(a.attach_id)')
                    ->from('EmployeeAttachment a')
                    ->where('a.emp_number = ?', $empNumber);
            $result = $q->execute(array(), Doctrine::HYDRATE_ARRAY);

            if (count($result) != 1) {
                throw new PIMServiceException('MAX(a.attach_id) failed.');
            }
            $attachId = is_null($result[0]['MAX']) ? 1 : $result[0]['MAX'] + 1;

        } else {
            $q = Doctrine_Query::create()
                    ->select('a.emp_number, a.attach_id')
                    ->from('EmployeeAttachment a')
                    ->where('a.emp_number = ?', $empNumber)
                    ->andWhere('a.attach_id = ?', $attachId);
            $result = $q->execute();

            if ($result->count() == 1) {
                $empAttachment = $result[0];
            } else {
                throw new PIMServiceException('Invalid attachment');
            }
        }

        //
        // New file upload
        //
        $newFile = false;

        if ($empAttachment === false) {

            $empAttachment = new EmployeeAttachment();
            $empAttachment->emp_number = $empNumber;
            $empAttachment->attach_id = $attachId;
            $newFile = true;
        }

        $commentOnly = $this->getValue('commentOnly');        
        if ($newFile || ($commentOnly == '0')) {
            $file = $this->getValue('ufile');
            echo "file==".$file;
            $tempName = $file->getTempName();

            $empAttachment->size = $file->getSize();
            $empAttachment->filename = $file->getOriginalName();
            $empAttachment->attachment = file_get_contents($tempName);;
            $empAttachment->file_type = $file->getType();
            $empAttachment->screen = $this->getValue('screen');

            $empAttachment->attached_by = $this->getOption('loggedInUser');
            $empAttachment->attached_by_name = $this->getOption('loggedInUserName');
            // emp_id and name
        }

        $empAttachment->description = $this->getValue('txtAttDesc');

        $empAttachment->save();
    }

}

But this code is only worked for single file not for zip file.

I want to upload and extract zip file.

j0k
  • 22,600
  • 28
  • 79
  • 90
  • What the size of your archive? – j0k Aug 09 '13 at 14:28
  • approx 60 MB and in future size may be exceed.Problem is that when i upload zip file i can not get zip file name and files remains in that zip folder. Do you have any idea how to upload and extract zip file in symfony 1.4? As i have read symfony documentation but there is only file upload examples, not contain any zip upload example. – user2667578 Aug 10 '13 at 03:53
  • Did you check that your php configuration allow file upload with a size of 60mb ? – j0k Aug 10 '13 at 10:34
  • So that's why Symfony didn't show you nothing, because uploads fail. Try to [increase these values](http://stackoverflow.com/a/2184541/569101) and give another try. Maybe, try with a fewer zip file, like 5mo – j0k Aug 12 '13 at 04:51
  • First if it accepts zip file from file upload control then the question comes of allowed upload file size.But when i upload zip file i am not able to get that zip file name and extract its content. While if i am uploading pdf,word,excel,image i am able to get file name easily.So my question is that why file upload conterol is not able to detect zip file, is anything is missing in my form? – user2667578 Aug 12 '13 at 05:15
  • Have you tried to add "application/zip" to mime types allowed in your sfValidatorFile ? You have to pass it in the "mime_types" options. Also, is your webserver configured to recognize .zip files as "application/zip" ? You can see that in /etc/mime.types for Ubuntu and Debian as well I guess. – sinhix Aug 16 '13 at 13:30

0 Answers0