为什么我的json_encode被破坏了

时间:2012-09-30 08:53:27

标签: yii json ajax-upload phpthumb

            $model = new XUploadForm;
            $model->file = CUploadedFile::getInstance( $model, 'file' );
            //We check that the file was successfully uploaded
            if( $model->file !== null ) {
                //Grab some data
                $model->mime_type = $model->file->getType( );
                $model->size = $model->file->getSize( );
                $model->name = $model->file->getName( );
                $file_extention = $model->file->getExtensionName( );
                //(optional) Generate a random name for our file
                $file_tem_name = md5(Yii::app( )->user->id.microtime( ).$model->name);
                $file_thumb_name = $file_tem_name.'_thumb.'.$file_extention;
                $file_image_name = $file_tem_name.".".$file_extention;
                if( $model->validate( ) ) {
                    //Move our file to our temporary dir
                    $model->file->saveAs( $path.$file_image_name );
                    if(chmod($path.$file_image_name, 0777 )){

     //                 Yii::import("ext.EPhpThumb.EPhpThumb");
                    // $thumb_=new EPhpThumb();
                 //      $thumb_->init();
                    // $thumb_->create($path.$file_image_name)
                    //  ->resize(110,80)
                    //  ->save($path.$file_thumb_name); 


                    }
                    //here you can also generate the image versions you need 
                    //using something like PHPThumb





                    //Now we need to save this path to the user's session
                    if( Yii::app( )->user->hasState( 'images' ) ) {
                        $userImages = Yii::app( )->user->getState( 'images' );
                    } else {
                        $userImages = array();
                    }
                     $userImages[] = array(
                          "filename" => $file_image_name,
                        'size' => $model->size,
                        'mime' => $model->mime_type,
                        "path" => $path.$file_image_name,
                       // "thumb" => $path.$file_thumb_name,
                    );
                    Yii::app( )->user->setState('images', $userImages);      
                    //Now we need to tell our widget that the upload was succesfull
                    //We do so, using the json structure defined in
                    // https://github.com/blueimp/jQuery-File-Upload/wiki/Setup
                    echo json_encode( array( array(
                            "type" => $model->mime_type,
                            "size" => $model->size,
                            "url" => $publicPath.$file_image_name,
                            //"thumbnail_url" => $publicPath.$file_thumb_name,
                            //"thumbnail_url" => $publicPath."thumbs/$filename",
                            "delete_url" => $this->createUrl( "upload", array(
                                "_method" => "delete",
                                "file" => $file_image_name
                            ) ),
                            "delete_type" => "POST"
                        ) ) );

以上代码给出了正确答案, [{ “类型”: “图像/ JPEG”, “大小”:2266, “URL”: “/上传/ TMP / 0b00cbaee07c6410241428c74aae1dca.jpeg”, “delete_url”:“/ API / imageUpload /上传_method =删除&安培;文件? = 0b00cbaee07c6410241428c74aae1dca.jpeg”, “delete_type”: “POST”}]

但如果我取消注释以下

         //     Yii::import("ext.EPhpThumb.EPhpThumb");
                // $thumb_=new EPhpThumb();
             //      $thumb_->init();
                // $thumb_->create($path.$file_image_name)
                //  ->resize(110,80)
                //  ->save($path.$file_thumb_name);   
它给了我腐败的反应:

Mac OSX2 ATTR dA Y Ycom.apple.quarantine0001; 50655994; Google \ x20Chrome.app; 2599ECF9-69C5-4386-B3D9-9F5CC7E0EE1D | com.google.Chrome此资源分叉故意留空[{ “类型”: “图像/ JPEG”, “大小”:1941, “URL”: “/上传/ TMP / 409c5921c6d20944e1a81f32b12fc380.jpeg”, “delete_url”:“/ API / imageUpload /上传_method =删除&安培? ;文件= 409c5921c6d20944e1a81f32b12fc380.jpeg”, “delete_type”: “POST”}]

1 个答案:

答案 0 :(得分:1)

我猜MacOS已经隔离了ext.EPhpTHumb.EPhpThumb或其中一个库的下载。

如果您知道该插件的安装位置,请尝试从终端中删除xattr -d com.apple.quarantine <filename>,或使用google remove mac os x quarantine status以获取其他方式。