|
 |
|
รบกวนดูโค้ดให้หน่อยนะค่ะ upload รูปภาพ อยากให้มัน resize อัตโนมัติ |
|
 |
|
|
 |
 |
|
โค้ด upload รูปภาพเข้าฐานข้อมูลได้แล้วแต่มันไม่ resize ให้ค่ะ รบกวนดูโค้ดให้หน่อยนะค่ะ
Code (PHP)
$filename=$_FILES['picture']['name'];
$filesize=$_FILES['picture']['size'];
$filetemp=$_FILES['picture']['tmp_name'];
$fileerror=$_FILES['picture']['error'];
$filetype=$_FILES['picture']['type'];
$ff = strrchr($filename,".");
$DIR_lenght=strlen($config[dataDir]) -1;
$DirOK = 0;
$DIR = opendir(".");
while ($text = readdir($DIR)){
if($text == substr($config[dataDir], 0, $DIR_lenght)) $DirOK = 1;
}
if($DirOK==0) mkdir($config[dataDir] ,0777);
$upload = strftime("%S%M%H").time().$ff;
$images = $picture;
//กำหนดความสูงของรูปใหม่
$height=100;
$size=GetimageSize($images);
$width=round($height*$size[0]/$size[1]);
$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,$config[dataDir1].$upfilename);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
$upfilename = $order_no.$ff;
$uploadfile = $config[dataDir] . $upfilename;
if (move_uploaded_file($_FILES['picture']['tmp_name'], "../upload/".$_FILES['picture']['name'])) {
echo "รูปแบบไฟล์ถูกต้อง อัพโหลดเรียบร้อย.\n";
} else {
echo "มีปัญหาการอัพโหลดไฟล์\n";
}
Tag : PHP, MySQL, CakePHP

|
|
 |
 |
 |
 |
Date :
2011-08-05 15:47:35 |
By :
chadjan |
View :
857 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
code มันไล่ยากครับ ว่าผิดตรงไหน ลองดูนี่แล้วกันครับ
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP Upload Resize</title>
</head>
<body>
<?
if(trim($_FILES["fileUpload"]["tmp_name"]) != "")
{
$images = $_FILES["fileUpload"]["tmp_name"];
$new_images = "Thumbnails_".$_FILES["fileUpload"]["name"];
move_uploaded_file($_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);
}
?>
<b>Original Size</b><br>
<img src="<?="MyResize/".$_FILES["fileUpload"]["name"];?>">
<hr>
<b>New Resize</b><br>
<img src="<?="MyResize/".$new_images;?>">
</body>
</html>
Go to : PHP Upload and Resize Image
|
 |
 |
 |
 |
Date :
2011-08-05 16:49:10 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|