php PHP警告getimagesize

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10321263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 21:54:44  来源:igfitidea点击:

PHP warning getimagesize

phpwarnings

提问by user979331

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

警告:getimagesize(../images/image-1Product 320120312100APPLE_IMG_0072.jpg) [function.getimagesize]:无法打开流:/home/content/44/8713044/html/admin/Home.php 上没有这样的文件或目录第 107 行

警告:imagecreatefromjpeg(../images/image-1Product 320120312100APPLE_IMG_0072.jpg) [function.imagecreatefromjpeg]:无法打开流:/home/content/44/8713044/html/admin/Home.php 中没有这样的文件或目录第122行

警告:imagecopyresampled():在第 128 行的 /home/content/44/8713044/html/admin/Home.php 中提供的参数不是有效的图像资源

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.

我知道为什么我因为第一个和第二个错误而收到第三个错误,我不知道为什么我收到 1 和 2 的警告,文件夹确实存在。

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

第 107 行 - $size = getimagesize($source);

第 122 行 - $image = imagecreatefromjpeg($source);

第 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

我将其更改为完整路径,但出现此错误 URL file-access is disabled in the server configuration

采纳答案by JonathanRomer

  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
  1. 尝试输入完整的 url 以路由到图像含义包括 http://
  2. 检查您对文件夹的权限,含义:正确 777

回答by AlonMichaeli

This problem is usually solved by reconfiguring the php.ini

这个问题一般通过重新配置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.

如果您使用的是 Wordpress 或任何其他 CMS,则可能由于安装了安全插件而出现问题。大多数安全插件都会更改 .htaccess 以防止对 url、目录和文件的未授权访问。

check your .htaccess and search for

检查您的 .htaccess 并搜索

RewriteRule ^.* - [F,L]

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

如果找到,请将其删除(#RewriteRule ^.* - [F,L])并检查它是否解决了您的问题。

回答by Warren Landis

Do you have GD installed an enabled?

你有没有安装启用的GD?

http://www.php.net/manual/en/image.installation.php

http://www.php.net/manual/en/image.installation.php

回答by Paul Dessert

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)

回答by M Rostami

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 变量指向错误的路径..
如果您在包含此代码的其他文件夹中包含一个 php 文件,请尝试使用这样的本地路径:

$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 .

如果您的图像文件夹位于第一个文件的根目录中,请不要使用“../”。