imagegif()没有上传到网站

时间:2014-03-22 07:33:54

标签: php

所以,我正在为我的网站制作一个头像脚本,并试图通过URL获取头像上传到网站。我已经确定允许所有内容(fopen或其他内容),但它似乎没有上传。我有一种感觉,问题是进程文件在/settings / process.php中,当它试图上传到/ useravatar时,但我不太确定。此外,query(),getuserdata()和getmydata()在代码中工作正常,因为它们是包含session.php中的函数

这是我的代码:

include('../session.php');
$pictureurl = $_POST['urlava'];
# CHECK THAT FILE IS NOT ACCESED DIRECTLY
if(isset($pictureurl)){
// CHECK IF POST IS "HTTP://" ONLY
if($pictureurl == 'http://'){
# IF YES, END SCRIPT
die("Error!");
}
# CHECK IF IT'S AN URL (HTTP/HTTPS)
$checkifurl = parse_url($pictureurl);
if($checkifurl['scheme'] == "http" || $checkifurl['scheme'] == "https"){
# CHECK IF IT'S AN IMAGE (PNG/JPG/JPEG/GIF/MPO)
$url = pathinfo($pictureurl);
if($url['extension'] == 'png' || $url['extension'] == 'jpg' || $url['extension'] == 'jpeg' || $url['extension'] == 'gif' || $url['extension'] == 'mpo'){
# DELETE CURRENT AVATAR
if(getuserdata($_SESSION['username'], avatar) == '/images/default.png'){
}else{
$file = substr(getmydata(avatar), 1);
unlink($file);
}
$randomstring = generateRandStr(5);
# CREATE NEW AVATAR
$img = file_get_contents($pictureurl);
$im = imagecreatefromstring($img);
$width = imagesx($im);
$height = imagesy($im);
$newwidth = '50';
$newheight = '50';
$thumb = imagecreatetruecolor($newwidth, $newheight);
    $filename = "/useravatar/".strtolower(getmydata(username))."-".$randomstring.".gif"; // I think the problem is here
imagecopyresampled($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagegif($thumb,$filename); // But it can also be here
imagedestroy($thumb);
imagedestroy($im);
# UPDATE AVATAR
query("UPDATE members SET avatar='$filename' WHERE username='$_SESSION[username]'");

}
}
}
header("Location: avatar.php?updated=1");

它可能看起来很乱,因为它可能是。这个脚本以前工作过,所以我不确定为什么它现在不起作用。如果有人可以提供帮助,那就太好了。提前谢谢。

1 个答案:

答案 0 :(得分:1)

问题是权限。

 Warning: unlink(): open_basedir restriction in effect. File() is not within the allowed path(s): (/var/customers/webs/ni235658_1/ring/ar7comm/:/var/customers/tmp/ni235658_1/:/usr/share/php/:/usr/share/php5/:/tmp/) in /var/customers/webs/ni235658_1/ring/ar7comm/settings/process.php on line 23

 Warning: imagegif(): Unable to open '/useravatar/-57Kkf.gif' for writing: No such file or directory in /var/customers/webs/ni235658_1/ring/ar7comm/settings/process.php on line 36

检查出来:http://secondchoice.de/点击发布插入网址 http://ar7comm.tk/settings/process.php并设置参数 urlava图片网址

尝试添加完整路径:

 imagegif($thumb, dirname(__FILE__) . '/' . $filename);