Uploading docx file in Zend Framework with mime type fails?

i am trying to upload resume to my website from users

so i have resticted the file upload too doc,pdf,and docx

ms word doc files are uploading fine along with pdf but docx files are coming in with

application/zip mime type so file does not get uploaded

how to do correct mime type checking so that docx file uploads as other files

below is my code

$config = Zend_Registry::get ( 'config' );

            $files_path = $config->resume->path;

            $adapter = new Zend_File_Transfer ();

            // Limit the MIME type of all given files to gif and jpeg images
            $adapter->addValidator ( 'MimeType', false, array ('application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/pdf' ) ); 


        $files = $adapter->getFileInfo ();


        $file_name = null;
        $tmpArr = null;

        foreach ( $files as $file => $info ) {
            if (! empty ( $info ['name'] )) {
                $tmpArr = explode ( ".", $info ['name'] );
            }
        }

        if (! empty ( $tmpArr )) {
            //$file_name = $tmpArr [0] . "-" . $post ['id'] . "." . $tmpArr [1];
            $file_name = $tmpArr [0] . "-" . $post ['id'] . "." . $tmpArr [count ( $tmpArr ) - 1];
            $adapter->setDestination ( $files_path );

            $adapter->addFilter ( 'Rename', array ('target' => $files_path . DS . $file_name, 'overwrite' => true ) );
            if ($adapter->receive ()) {
                // # =  # = # = # = # = # = # = # = # = # = # = # = # = # = # = # = # =
                $arrayKeys = array_keys ( $files );
                $actual_file_name = $tmpArr [0] . "." . $tmpArr [1];
                $uploaded_file_name = $adapter->getFileName ( $arrayKeys [0], false );
                if ($actual_file_name == $uploaded_file_name) {
                    rename ( $files_path . DS . $actual_file_name, $files_path . DS . $file_name );
                }
                // # =  # = # = # = # = # = # = # = # = # = # = # = # = # = # = # = # =


                $post ['filename'] = $file_name;
                $result = $employeeModel->updateEmployeeResume ( $post );
                $old_file = $files_path . DS . $post ['c_image_name'];
                if (file_exists ( $old_file )) {
                    @unlink ( $old_file );
                }

                $this->_flashMessenger->addMessage ( 'Resume added successfully' );
            }

DOCX基本上是一个ZIP文件(你可以用你最喜欢的解压缩工具将它们解压缩,试一试!),所以如果你希望你的用户能够上传DOCX文件,你必须允许ZIP文件。


i have added a temporaray fix in zend

// allowing zip files to upload

     $adapter->addValidator ( 'MimeType', false, array ('application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/pdf','application/zip' ) );

// disallowing files with .zip to upload and getting docx files uploaded hence .

    $adapter->addValidator('Extension', false, 'doc,docx,pdf');
链接地址: http://www.djcxy.com/p/46786.html

上一篇: MIME类型用于在不同浏览器中以PHP上传PDF

下一篇: 在Zend Framework中使用MIME类型上传docx文件失败?