コントローラのアクションでimagecreatefrompng()を使用すると、コードが壊れます。違いはないと思いますが、imagecreatefrompng()は、AJAXを介して呼び出されたアクション内で呼び出されます。
$imgName='img/favicons/'.$saveFileName.'_large.png';
$img=imagecreatefrompng($imgName);
私は道が正しいとかなり確信しています。同じアクションで、ファイルをそのフォルダーに保存しますが、次のエラーが返されます。
警告:get_class()は、パラメーター1がオブジェクトであり、リソースが578行のC:\ xampp \ htdocs \cakephp \ lib \ Cake \ Utility\Debugger.phpで指定されていることを想定しています。
警告:get_object_vars()は、パラメーター1がオブジェクトであると想定しています。リソースはC:\ xampp \ htdocs \cakephp \ lib \ Cake \ Utility\Debugger.phpの584行目にあります。
エラーが指すdebugger.phpファイルの特定の関数は、オブジェクトから文字列への変換を処理し、エラーの原因となる行は次のとおりです。
$className = get_class($var);
$objectVars = get_object_vars($var);
誰かが何が悪いのか考えていますか?ありがとう
編集 :
関数のコードは次のとおりです
public function saveSiteFavicon() {
$this->layout = 'ajax';
$url = $this->request->data['websiteurl'];
$saveFileName = parse_url($url);
$saveFileName = $saveFileName['host'];
$saveFileName = str_replace('.', '', $saveFileName);
$saveFileName = str_replace('www', '', $saveFileName);
$this->Favicon->recursive = 0;
$faviconexists = $this->Favicon->findByImage($saveFileName.'.png');
if(!empty($faviconexists)) {
echo $saveFileName.'.png:'.$faviconexists['Favicon']['id'];
} else {
$fp = fopen ('img/favicons/'.$saveFileName.'.png', 'w+');
$ch = curl_init('http://g.etfv.co/'.$url);
curl_setopt($ch, CURLOPT_TIMEOUT, 6);
/* Save the returned data to a file */
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
//if the favicon is oversized resize it
$faviconFileName = 'img/favicons/'.$saveFileName.'.png';
$metaData=getimagesize($faviconFileName);
if($metaData[1] > 16) {
rename($faviconFileName, 'img/favicons/'.$saveFileName.'_large.png');
$imgName='img/favicons/'.$saveFileName.'_large.png';
$thumbName='img/favicons/'.$saveFileName.'.png';
$img=imagecreatefrompng($imgName);
$imgThumb=imagecreatetruecolor(16,16);
imagecopyresampled($imgThumb,$img,0,0,0,0,16,16,$metaData[0],$metaData[1]);
imagepng($imgThumb, $thumbName);
imagedestroy($imgThumb);
}
$this->Favicon->create();
$this->Favicon->save(array('image'=>$saveFileName.'.png'));
$faviconid = $this->Favicon->getLastInsertId();
echo $saveFileName.'.png:'.$faviconid;
}
}
ビューでは、ajaxを介してこの関数を呼び出し、エラーメッセージが表示される結果にアラートを送信します。
$.post("../favicons/saveSiteFavicon", {websiteurl: value})
.done(function(data) {
alert(data);
});