php - imagegif() not uploading to site

759

So, I'm working on an avatar script for my site and am trying to get avatars by URL to upload to the site. I already made sure that everything (fopen or something along those lines) was allowed, but it just doesn't seem to upload. I have a feeling that the problem is the process file is in /settings/process.php while it's trying to upload to /useravatar, but I'm not really sure. Also, query(), getuserdata(), and getmydata() are working fine in the code, as they are functions in the included session.php

Here's my code:

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

It may seem messy, because it probably is. This script worked before, so I'm unsure why it doesn't work now. If anyone could help, that would be great. Thanks in advance.

540

Answer

Solution:

Problem is the Permissions.

 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

Check it out: http://secondchoice.de/ click on POST insert the Url http://ar7comm.tk/settings/process.php and set the Parameter urlava with an Image url

Try to add the full path:

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

People are also looking for solutions to the problem: arrays - PHP mapping through exploded string inserts weird [] at the end

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.