|
|
|
php คือจะ rename ก่อนอัพโหลด upload ครับต้องแทรกโค้ดตรงไหนครับ |
|
|
|
|
|
|
|
Code (PHP)
if(trim($_FILES["fileUpload"]["tmp_name"]) != "")
{
$images = $_FILES["fileUpload"]["tmp_name"];
$new_images = "Thumbnails_".$_FILES["fileUpload"]["name"];
copy($_FILES["fileUpload"]["tmp_name"],"MyResize/".$_FILES["fileUpload"]["name"]);
$width=100; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round($width*$size[1]/$size[0]);
$images_orig = ImageCreateFromJPEG($images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
ImageJPEG($images_fin,"MyResize/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
echo "Resize Successful.<br>";
}
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2013-03-28 10:27:45 |
By :
dagonov |
View :
1258 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?
if(trim($_FILES["fileUpload"]["tmp_name"]) != "")
{
$explode=explode(".",$_FILES["fileUpload"]["name"]); // ตัดนามสกุล
$random=rand(); // random number
$Tmprename="Tmp-".$random.".".$explode[1]; // rename picture
$rename=$random.".".$explode[1]; // rename picture
copy($_FILES["fileUpload"]["tmp_name"],"MyResize/".$rename);
$width=100; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round($width*$size[1]/$size[0]);
$images_orig = ImageCreateFromJPEG($images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
ImageJPEG($images_fin,"MyResize/".$Tmprename);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
$insert=mysql_query("INSERT INTO tb_example (Tmp,Picture) VALUES ('".$Tmprename."','".$rename."')") or die (mysql_error());
if($insert){
echo "Resize Successful";
}
}
?>
|
ประวัติการแก้ไข 2013-03-28 10:37:30
|
|
|
|
Date :
2013-03-28 10:35:30 |
By :
Ex-[S]i[L]e[N]t |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อยากให้อัพไฟล์.png ได้ด้วยครับทำไง
|
|
|
|
|
Date :
2013-03-28 10:43:35 |
By :
dagonov |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?
if(trim($_FILES["fileUpload"]["tmp_name"]) != "")
{
$images=$_FILES["fileUpload"]["tmp_name"];
$explode=explode(".",$_FILES["fileUpload"]["name"]); // ตัดนามสกุล
$random=rand(); // random number
$Tmprename="Tmp-".$random.".".$explode[1]; // rename picture
$rename=$random.".".$explode[1]; // rename picture
copy($_FILES["fileUpload"]["tmp_name"],"MyResize/".$rename);
$width=100; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round($width*$size[1]/$size[0]);
if($explode[1] == 'jpg' || $explode[1] == 'jpeg'){ // กรณี่ .jpeg
$images_orig = imagecreatefromjpeg($images);
}else if($explode[1] == 'png'){ // กรณี .png
$images_orig=imagecreatefrompng($images);
}
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
if($explode[1] == 'jpg' || $explode[1] == 'jpeg'){ // กรณี่ .jpeg
imagejpeg($images_fin,"MyResize/".$Tmprename);
}else if($explode[1] == 'png'){ // กรณี .png
imagepng($images_fin,"MyResize/".$Tmprename);
}
ImageDestroy($images_orig);
ImageDestroy($images_fin);
$insert=mysql_query("INSERT INTO tb_example (Tmp,Picture) VALUES ('".$Tmprename."','".$rename."')") or die (mysql_error());
if($insert){
echo "Resize Successful";
}
}
?>
|
|
|
|
|
Date :
2013-03-28 10:53:33 |
By :
Ex-[S]i[L]e[N]t |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|