Yii 为什么我的json_编码会损坏
上面的代码给了我正确的回答, [{“type”:“image/jpeg”,“size”:2266,“url”:“/uploads/tmp/0B00CBAE07C6410241428C74AAE1DCA.jpeg”,“delete_url”:“/api/imageUpload/upload?_method=delete&file=0B00CBAE07C6410241428C74AAE1DCA.jpeg”,“delete_type”:“POST”] 但如果我取消注释以下内容Yii 为什么我的json_编码会损坏,yii,json,ajax-upload,phpthumb,Yii,Json,Ajax Upload,Phpthumb,上面的代码给了我正确的回答, [{“type”:“image/jpeg”,“size”:2266,“url”:“/uploads/tmp/0B00CBAE07C6410241428C74AAE1DCA.jpeg”,“delete_url”:“/api/imageUpload/upload?_method=delete&file=0B00CBAE07C6410241428C74AAE1DCA.jpeg”,“delete_type”:“POST”] 但如果我取消注释以下内容
$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"
) ) );
它给了我错误的回答:
MacOSX2��属性�dA��Y�Ycom.apple.Quarantine001;50655994;Google\x20Chrome.app;2599ECF9-69C5-4386-B3D9-9F5CC7E0EE1D | com.google.chrometh此资源分叉故意留空��[{“type”:“image/jpeg”,“size”:1941,“url”:“/uploads/tmp/409c5921c6d20944e1a81f32b1fc380.jpeg”,“delete_-url”:/api/imageUpload/upload?_-method=delete&file=409c5921c6d20944e1a81f32b1fc380.jpeg”,“delete_-type”:“POST”}我猜MacOS已经隔离了您下载的
ext.ephthumb.epthumb.eph
如果你知道插件的安装位置,请尝试从终端上删除它,或者用谷歌
删除mac os x隔离状态
找到其他方法。朋友们,请帮帮我,我几乎被这个问题烧焦了,因为在图像出现之前屏幕上打印了一些东西,很可能是您刚刚取消注释的代码。。。检查这些新未注释的行的作用。谢谢。我还是不知道。实际上,注释代码用于生成缩略图。我确实看到了成功生成的文件。你是说那些代码的“回声/打印”吗?嗨,约阿希姆,你真棒。我的mac电脑是问题的根源。我没有费心删除Mac中的隔离,但我从Windows中删除并读取了插件。神奇的事情发生了,它解决了问题。非常感谢。如果你在下面提供答案,我可以接受你的答案。Thx。在开发网站的过程中,我的Mac电脑给了我很多问题
// Yii::import("ext.EPhpThumb.EPhpThumb");
// $thumb_=new EPhpThumb();
// $thumb_->init();
// $thumb_->create($path.$file_image_name)
// ->resize(110,80)
// ->save($path.$file_thumb_name);