注意:未定义偏移:0 错误
我不断收到以下错误,但我不知道如何修复它!帮助!
注意:未定义的偏移量:第 51 行 C:\public_html\admin\includes\funcs.inc.php 中的 0
我确实得到了警告输出错误...
function getFileExtension($key) {
$extensions = array(IMAGETYPE_GIF => '.gif', IMAGETYPE_JPEG => '.jpg', IMAGETYPE_PNG => '.png');
$exifType = exif_imagetype($_FILES['artwork']['tmp_name'][$key]);
LINE 51 ---> $ext = $extensions[$exifType];
return $ext;
}
$ext = getFileExtension($key);
if (!isset($ext)) {
$warning = 'Error: Unsupported file type (supported images: gif, jpeg, png).';
}
i keep getting the following error and i don't no how to fix it! Help!
Notice: Undefined offset: 0 in C:\public_html\admin\includes\funcs.inc.php on line 51
i do get the warning output error thought...
function getFileExtension($key) {
$extensions = array(IMAGETYPE_GIF => '.gif', IMAGETYPE_JPEG => '.jpg', IMAGETYPE_PNG => '.png');
$exifType = exif_imagetype($_FILES['artwork']['tmp_name'][$key]);
LINE 51 ---> $ext = $extensions[$exifType];
return $ext;
}
$ext = getFileExtension($key);
if (!isset($ext)) {
$warning = 'Error: Unsupported file type (supported images: gif, jpeg, png).';
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
似乎您还没有用逗号声明数组键:
尝试使用这个 :
如果它有效,请告诉我。
Seems that you haven't declared the array keys with commas:
try to use this :
And please let me know if it works.
如果 exif_imagetype() 返回的值不是您在数组中定义的值,您将收到偏移错误。防止这种情况的更好解决方案是在设置返回值之前测试数组键是否存在。
已更新以测试 $exifType 中的值,因此不会导致 array_key_exists() 失败。
You will receive an offset error in any case that exif_imagetype() returns a value that you do not have defined in your array. A better solution to prevent this is to test for the existence of the array key before you set your return value.
Updated to test for a value in $exifType so it doesn't cause array_key_exists() to fail.
exif_imagetype 的文档表明它返回
false
当未检测到有效签名时。如果您尝试$extensions[false]
您将收到偏移错误,因此这可能就是正在发生的情况。The documentation for exif_imagetype indicates that it returns
false
when a valid signature is not detected. If you try$extensions[false]
you'll get your offset error, so this is probably what is occurring.您检查 $_FILES['artwork']['tmp_name'] 是否不为空吗?
我猜你的文件没有上传。
您应该提供更多详细信息或一些调试
信息
Did you check if $_FILES['artwork']['tmp_name'] isn't empty ?
I suppose that your file wasn't uploaded.
You should provide more details or some debug informations
Greetings