我在PHP中编写了一个脚本来上传图像.
到目前为止,我的目标是上传并向服务器发送2个图像,1个原始图像和1个缩略图.我的脚本有效,但并不完美.这是我的剧本
<?php
//this is script for get data type file
$acak = rand(000000,999999);// for random
$lokasi_file = $_FILES['fupload']['tmp_name'];
$nama_file = $_FILES['fupload']['name'];
$nama_file_acak = $acak.$nama_file;
$ukuran_file = $_FILES['fupload']['size'];
$tipe_file = $_FILES['fupload']['type'];
$direktori = "fkendaraan/$nama_file_acak";
$uplod = move_uploaded_file($lokasi_file,"$direktori"); //to move image from local to the server folder
//to handle uplod thumbnail image
$img = imagecreatefromjpeg($direktori);
$width = imagesx($img);
$height = imagesy($img);
$new_width = 200;
$new_height = ($new_width/$width) * $height;
$tmp_img = imagecreatetruecolor( $width, $height );
imagecopyresampled( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
//imagecopyresized( $tmp_img, $img, 200, 200, 0, 0, $new_width, $new_height, $width, $height );
imagejpeg( $tmp_img, $direktori."thumb-".$nama_file_acak );
imagedestroy($tmp_img);
imagedestroy($direktori);
Run Code Online (Sandbox Code Playgroud)
// ------------------------------------------------ ---------------
//I have no Problem with query and database, it works fine
$sql = "";
$query = mysql_query($sql);
?>
Run Code Online (Sandbox Code Playgroud)
这可以运行但不完美,因为结果是这样的


任何人都可以帮我解决这个问题?我非常nubie在PHP
尝试改变这个:
$tmp_img = imagecreatetruecolor( $width, $height );
Run Code Online (Sandbox Code Playgroud)
对此:
$tmp_img = imagecreatetruecolor( $new_width, $new_height );
Run Code Online (Sandbox Code Playgroud)
无论如何,我建议你使用一些类来完成这些任务,例如: Shiege Iseng Resize Class.
但是,当然,如果你想用这个来学习,那没关系:)
| 归档时间: |
|
| 查看次数: |
172 次 |
| 最近记录: |