SimpleImage.php(再次)没有错误但没有工作

时间:2012-04-18 10:51:05

标签: php file-upload

好的,我在这个剧本上看过很多帖子。哪个可以找到......

http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/

然而,我仍然无法使其与我所拥有的一起工作。所以这就是问题所在。首先,我上传图像并将名称保存到数据库中。然后,我将其ID传递到下一页,以从数据库中检索图像及其路径。这是脚本的用武之地。然后我通过脚本运行图像并将您发送到成功页面。

现在图像没有调整大小!代码没有错误(即使报告错误)。它似乎完全被忽略了。图像仍然存在,并显示它的上传方式,但尺寸没有改变。我正在以正确的方式使用它。以下是图片上传后的代码。

$Fetchq = mysql_query("SELECT * FROM images WHERE imageID ='".$_GET['image']."' ") or die('error stuff here');
$fetched = mysql_fetch_array($Fetchq);


$path = "/members/images/members/merseyside/{$fetched['imagename']}";


include('SimpleImage.php');
$image = new SimpleImage();
$image->load('$path');
$image->resize(60,60);   
$image->save('$path');



 $url = "/activity-photos.php?uploaded=true";        
header("Location: $url"); 

任何帮助都会非常感激,因为我已经有足够的力量打击这个代码墙了

1 个答案:

答案 0 :(得分:2)

$image->save('$path');

如果在单引号内使用变量,则将其视为实际字符串而不是变量值。

解决方案:

$image->save( $path ); // Remove the quotes

$image->save( "$path" ); // Replace with double quotes

编辑:

另外,请务必同时更改$image->load()

...
$image = new SimpleImage();
$image->load( $path ); // Removed quotes
$image->resize(60,60);   
$image->save( $path ); // Removed quotes
...

您可以在此处了解有关字符串插值的更多信息:

http://php.net/manual/en/language.types.string.php

相关问题