I wrote the following script one year ago to enable people to upload pictures on a custom forum. I'm sure it works correctly, would you mind trying it?
$userfile is the local filename obtained with a "browse" control on a form on the previous page.
The picture is uploaded to a temp folder, then I perform some tests on it, and if everything is ok, I copy it to its final folder.
if my member name ($logged_name) is toto, the name of my file on the server will be _toto.jpg
if you want you can modify the script to suit your needs and see if your problem remains.
chmod("../../forum/avatars/tmp", 0777);
chmod("../../forum/avatars", 0777);
copy($userfile, "../../forum/avatars/tmp/$userfile_name");
//size checking
$taille = getimagesize("../../forum/avatars/tmp/$userfile_name");
$largeur = $taille[0];
$longeur = $taille[1];
if($largeur <= 90 && $longeur <= 90 && $userfile_size <= 50600)
{
// format checking
$extension = substr($userfile_name, -4);
if($extension != ".jpg" && $extension != ".gif")
{
$erreur = "bad format: seul. .gif et .jpg";
$i++;
}
else
{
if(!isset($erreur))
{
copy($userfile, "../../forum/avatars/_$logged_name$extension");
if($extension == ".jpg")
{
@unlink("../../forum/avatars/_$logged_name.gif");
}
else
{
@unlink("../../forum/avatars/_$logged_name.jpg");
}
}
}
}
else
{
$erreur = "this picture is too large, max 90 x 90 (25ko)";
$i++;
}
unlink("../../forum/avatars/tmp/$userfile_name");