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'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置