0
可能重複:
How to convert all images to JPG format in PHP?外匯牌價用戶圖像,以JPG
我想要的用戶名進入文件名,並有文件,.jpg結尾所以輸出將成爲「user-mycoolnewimage.jpg」。關於如何做到這一點的任何建議都改爲「randnumber-mycoolnewimage.png」,這不是我想要的。隨機數對服務器日誌沒有幫助,並且圖像需要以jpg格式結束,因爲它正在被轉換。
$file = rand(0, 10000000).$_FILES['t1']['name'];
if (move_uploaded_file($_FILES['t1']['tmp_name'], $file)) {
if($fp = fopen($file,"rb", 0)) {
$picture = fread($fp,filesize($file));
fclose($fp);
$image = imagecreatefrompng($file);
imagejpeg($image, $file, 70);
imagedestroy($image);
$tag1 = '<img src="'.$file.'" alt="" class="default" />';
//unlink($file);
}
}