douyue1998 2012-09-06 11:47
浏览 62
已采纳

PHP GD功能无法识别

So Im trying to make a script that uses PHP GD to upload and resize an image. Then save it to the database. I used the SImpleImage.php found here:

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

And implemented the code using the following script:

 $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 is a variable attached to a form field. Ive been playing about with it, and made sure my server has GD installed, and that the SimpleImage.php file is uploaded correctly. But I keep getting loads of errors.

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

All of them relating to SimpleImage.php, which I did not write, seems like it makes sense, and that I know other people have implemented successfully. The majority of the errors are to the one above. Does anyone have any ideas where this problem may be stemming from?

  • 写回答

1条回答 默认 最新

  • duan2428 2012-09-06 12:48
    关注

    You can't get a file from a HTML form with $_POST. To upload a file you need this field in your form:

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

    In your PHP script you have to change the first line:

    $myfilename=$_FILES['attachments']['tmp_name'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?