PHP warning getimagesize [duplicate]

2019-01-20 17:47发布

I am getting these errors when trying to upload an image to the server

Warning: getimagesize(../images/image-1Product 320120312100APPLE_IMG_0072.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/content/44/8713044/html/admin/Home.php on line 107

Warning: imagecreatefromjpeg(../images/image-1Product 320120312100APPLE_IMG_0072.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/content/44/8713044/html/admin/Home.php on line 122

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/content/44/8713044/html/admin/Home.php on line 128

I know why I am getting the third error because of the 1st and 2nd error, I dont why I am getting warnings for 1 and 2, the folder does exist.

Line 107 - $size = getimagesize($source);

Line 122 - $image = imagecreatefromjpeg($source);

Line 128 - imagecopyresampled($new_image,$image,0,0,$x,$y,$thumb_width,$thumb_width,$width,$height);

If anyone has got any tips It would be much appreciated.

I changed it over to the full path, but got this error URL file-access is disabled in the server configuration

标签: php warnings
5条回答
我想做一个坏孩纸
2楼-- · 2019-01-20 18:19
  1. Try to enter the complete url to route to the image meaning include the http://
  2. Check your rights on the folders meaning : Right 777
查看更多
乱世女痞
3楼-- · 2019-01-20 18:23
Deceive 欺骗
4楼-- · 2019-01-20 18:35

your $source variable is point to wrong path ..
if you include a php file in other folder that contains this code , try to use local path like this :

$source='images/image-1Product 320120312100APPLE_IMG_0072.jpg';
$size = getimagesize($source);

don't use '../' if your images folder is in root that first file is there .

查看更多
Explosion°爆炸
5楼-- · 2019-01-20 18:42

Try and remove the space from your file name. I had a problem like this once, and I believe removing the space fixed it.

Change:

image-1Product 320120312100APPLE_IMG_0072.jpg)

To:

image-1Product320120312100APPLE_IMG_0072.jpg)
查看更多
We Are One
6楼-- · 2019-01-20 18:44

This problem is usually solved by reconfiguring the php.ini

allow_url_fopen = On

To do that, you might need to contact your hosting provider.

If you're using Wordpress or any other CMS, it might accure due to a security plugin that's installed. Most security plugins change the .htaccess in order to prevent unauthorized access to url's, directories and files.

check your .htaccess and search for

RewriteRule ^.* - [F,L]

if you find it, remove it (#RewriteRule ^.* - [F,L]) and check if it fixed your problem.

查看更多
登录 后发表回答