无法使用php-image-magician保存图像

时间:2013-07-01 00:23:42

标签: php html

我正在尝试调整大小,然后使用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>

请解释我该做什么,以及我做错了什么。

等待你的回复

关于

2 个答案:

答案 0 :(得分:0)

我想你忘了在

中添加$savepath的文件名
saveImage($savepath, ... )

修改

这是源代码的一部分:

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

答案 1 :(得分:0)

你的savepath应该是精确的图片链接!不仅是文件夹名称,还应包括文件名和格式。

尝试:

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