$img_size and $height > $img_size){ //imagesizeが大きかったら if($width > $height){ $percent = $img_size / $width; //パーセンテージを設定 }else{ $percent = $img_size / $height; } }else{ if($width > $img_size){ $percent = $img_size / $width; }elseif($height > $img_size){ $percent = $img_size / $height; } } //サイズを設定 $newwidth = $width * $percent; $newheight = $height * $percent; //TrueColor イメージを新規に作成する $thumb = imagecreatetruecolor($newwidth, $newheight); if($imgtype == 'jpg' //ファイル又は URL から新規 JPEG 画像を作成する $source = imagecreatefromjpeg($img_tmp); //リサイズ imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagejpeg($thumb, $FilePath,100); } return $FilePath; } " />

itoigawabass

itoigawaのブログ

php備忘録

2011-01-05

大きいfileがupload出来ないのを修正した。
php.iniのpost_max_sizeとupload_max_filesizeを修正、post_max_sizeはupload_max_filesize より大きく設定する必要があります。
configureスクリプトでメモリ制限を有効とした場合、memory_limitも ファイルアップロードに影響します。
一般的に memory_limit は、 post_max_sizeよりも大きく する必要があります。
formのMAX_FILE_SIZEを修正、MAX_FILE_SIZE は、必ず "file" input フィールドより前になければなりません

uploadimageのサイズ変更と保存

function image_s($img_tmp,$img_name,$img_size){
$FilePath = false;
if($img_tmp != ""){
$f = strrev($img_name);
$ext = substr($f, 0, strpos($f,"."));
$imgtype = strrev($ext);		//拡張子を得る
$FilePath = "./images/".date("Ymdhis") . "." . $imgtype;	//timeでfilenameを設定
list($width, $height) = getimagesize($img_tmp);		//サイズを得る
$percent = 1;
if($width > $img_size and $height > $img_size){		//imagesizeが大きかったら
if($width > $height){
$percent = $img_size / $width;				//パーセンテージを設定
}else{
$percent = $img_size / $height;
}
}else{
if($width > $img_size){
$percent = $img_size / $width;
}elseif($height > $img_size){
$percent = $img_size / $height;
}
}
//サイズを設定
$newwidth = $width * $percent;
$newheight = $height * $percent;
//TrueColor イメージを新規に作成する
$thumb = imagecreatetruecolor($newwidth, $newheight);
if($imgtype == 'jpg'
//ファイル又は URL から新規 JPEG 画像を作成する
$source = imagecreatefromjpeg($img_tmp);
//リサイズ
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, $FilePath,100);
}
return $FilePath;
}

カテゴリー:blog
タグ: