0

好的,我看过很多关于这个脚本的帖子。哪个可以找到.....

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"); 

任何帮助将不胜感激,因为我已经受够了将头撞在这堵代码墙上

4

1 回答 1

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

于 2012-04-18T10:58:29.380 回答