2013-07-01 15 views
0

我正在嘗試調整大小,然後使用php-image-magician上傳圖像。但我無法保存圖像。請看看代碼:無法使用php-image-magician保存圖像

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="utf-8" /> 
<title>Upload</title> 
</head> 
<body> 
<?php 

if (isset($_POST['submit'])) { 

require_once('php-image-magician/php_image_magician.php'); 


// *** Step 1 of 2) Set up the variables 
$formInputName = 'img-upload';       # This is the name given to the form's file input 
$savePath  = 'output3';        # The folder to save the image 
$saveName  = 'test';         # Without ext 
$allowedExtArray = array('.jpg', '.png', '.gif', '.bmp'); # Set allowed file types 
$imageQuality = 100; 


// *** If the form has been submitted...  
if (isset($_POST['submit'])) { 
$error = '';   

// *** Create object 
$magicianObj = new imageLib($formInputName, $savePath, $saveName , $allowedExtArray); 

// *** If everything is swell, continue... 
if ($umagicianObj->getIsSuccessful()) { 
#=------------------------------------------------------------------ 

// *** Step 2 of 2) Add your image processing code here. 

$magicianObj -> resizeImage(100, 100); 
$magicianObj -> greyScaleDramatic(); 

#=------------------------------------------------------------------   
$magicianObj -> saveImage($savepath, $imageQuality); 
} else { 

// *** If there was an error, save it. 
$error = $magicianObj->getError(); 
} 

} 
// *** Display 
echo '<img src="' . $magicianObj->$savepath() . '">'; 
} 

?> 

<!-- The form. Not the name "img-upload" --> 
<form action="" method="POST" enctype="multipart/form-data"> 
<input type="file" name="img-upload" value="" /> 
<input type="submit" value="upload" name="submit" /> 
</form> 

</body> 
</html> 

請解釋我該怎麼做,以及我做錯了什麼。

等待你的答覆

與問候

回答

0

我想你忘記文件名中添加$savepath

saveImage($savepath, ...) 

編輯:

它的源代碼的一部分:

public function saveImage($savePath, $imageQuality="100") 
# Param in: $savePath: Where to save the image including filename: 
0

你的savepath應該是精確的圖像鏈接!不僅文件夾名稱,它還應包括文件名和格式。

嘗試:

saveImage($savepath.$savename.".jpg", $imageQuality)