无法识别PHP GD函数


PHP GD Functions not being recognised

所以我试图制作一个使用PHP GD上传和调整图像大小的脚本。然后将其保存到数据库中。我使用了在这里找到的SImpleImage.php:

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

并使用以下脚本实现了代码:

 $myfilename=$_POST['attachments'];
require('SimpleImage.php');
  $image = new SimpleImage();
  $image->load($myfilename);
  $image->resizeToWidth(150);
  $image->save('small-'.$myfilename);
  $image->load($myfilename);
  $image->resizeToWidth(230);
  $image->save('big-'.$myfilename);

myfilename是一个附加到表单字段的变量。我一直在玩它,并确保我的服务器安装了GD,并且SimpleImage.php文件上传正确。但我总是犯很多错误。

Warning: imagesy(): supplied argument is not a valid Image resource in (File Path).php on line 77

所有这些都与我没有写的SimpleImage.php有关,这似乎是有道理的,而且我知道其他人已经成功地实现了。大多数错误都与上面的错误有关。有人知道这个问题的根源吗?

使用$_POST无法从HTML表单中获取文件。要上传文件,您需要在表单中填写以下字段:

<input type="file" name="attachments">

在PHP脚本中,您必须更改第一行:

$myfilename=$_FILES['attachments']['tmp_name'];