2011-02-17 169 views
0

好吧,上傳後調整圖片大小,無法正常工作?

所以我有一個PHP文件,上傳圖像到我的服務器。上傳後,我想將圖像大小調整爲100X100文件。下面是我的代碼不起作用。

請幫忙!

<?php 
include 'resize.image.class.php'; 

$get_username = "usernamehere"; 
$new_id = "19"; 

$uploadDir = "./../users/$get_username/pictures/"; 
$file = basename($_FILES['userfile']['name']); 
$uploadFile = $file; 
$newName = $uploadDir . $new_id . $uploadFile; 
$file_size = $_FILES['userfile']['size']; 

if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { 

    $image = new Resize_Image; 
    $image->new_width = 100; 
    $image->new_height = 100; 
    $image->image_to_resize = "./../users/$get_username/pictures/$new_id.jpg"; // Full Path to the file 
    $image->ratio = true; 
    $image->new_image_name = "$new_id"; 
    $image->save_folder = "./../users/$get_username/pictures/thumbnails/"; 
    $process = $image->resize(); 

} 

?> 

這是一個簡化版本。但是,當我單獨運行調整大小的代碼時,代碼工作。思考?

再次感謝!

+0

有什麼錯誤?什麼是resize.image.class.php? – Jacob 2011-02-17 05:55:00

+0

唯一的錯誤:該文件不存在。 – iosfreak 2011-02-17 05:56:22

回答

1

您錯誤地指定了'源'文件名。源文件必須由temp_name事物訪問。所以,這行代碼中的故障:

$image->image_to_resize = "./../users/$get_username/pictures/$new_id.jpg"; 

相反,這樣做:

$image->image_to_resize = $_FILES['userfile']['tmp_name'];