Cross-browser PHP? WTF?
Hey guys.. Here's one for you...
On one of my sites, I am using PHP and (duh) forms to allow the upload of pictures... Works fine in mozzie... Works fine in IE - but get into Safari and other browsers I get raped.
Anyways... Here's the PHP:
if($submit)
{
$uploaddir = 'public_html/members/uploads/';
$imtype=$_FILES["userfile"]["type"];
$filename = $mpage->IdNum;
if ($imtype == "image/pjpeg"{
$extension=".jpg";
} elseif ($imtype == "image/gif" {
$extension=".gif";
} else {
echo "< center >< span class=\"error\"> Please upload images with the extension .jpg or .jpeg or .gif or .png only< /span >< /center >";
$mpage->ClosePage();
}
if (move_uploaded_file($_FILES['userfile'][ 'tmp_name'], $uploaddir . $filename . $extension)) {
$file = "$filename" . "$extension" ;
$sql = "UPDATE UserTable SET Filename=\"$file\" WHERE Id='$mpage->IdNum'" ;
$svr->DoQuery($sql);
echo "SUCCESS! You have uploaded your personal image, which will now be displayed on your personal homepage. Now just close this window, and resume editing your profile.";
$mpage->ClosePage();
}
else {
print "Possible file upload attack! You have been reported.";
}
$mpage->ClosePage();
}
Obviously I changed a couple things prior posting this code, but just for security of my site... Now... here's the HTML:
< form enctype="multipart/form-data" action="../members/setupimage.php" method=" post" >
< h3 >Upload A Photo< /h3 >
You are permitted one file that will be uploaded to our servers. It is required to be either a .jpg file or a .gif file, and required to be a real photo of you. Images that do not follow these restrictions will be deleted, and your account subject to deletion.
< input type="hidden" name="MAX_FILE_SIZE" value="100000000" >
Upload Now: < input name="userfile" type="file" >
< input type="submit" name="submit" value=" upload file" >
< /form >
Now, after a bit more probing on DeviantArt, I found out a possible reason it's not uploading in some browsers:
The problem is the browser, moreover the way in which the browser accesses and sends data.
PHP can only recieve uploads from RFC-1867 compliant browsers, such as Netscape or Internet Explorer. (I'm pretty sure that Opera also works fine).
Can someone PLEASE help me with a solution? It's driving me nuts!
-Shade
On one of my sites, I am using PHP and (duh) forms to allow the upload of pictures... Works fine in mozzie... Works fine in IE - but get into Safari and other browsers I get raped.
Anyways... Here's the PHP:
if($submit)
{
$uploaddir = 'public_html/members/uploads/';
$imtype=$_FILES["userfile"]["type"];
$filename = $mpage->IdNum;
if ($imtype == "image/pjpeg"{
$extension=".jpg";
} elseif ($imtype == "image/gif" {
$extension=".gif";
} else {
echo "< center >< span class=\"error\"> Please upload images with the extension .jpg or .jpeg or .gif or .png only< /span >< /center >";
$mpage->ClosePage();
}
if (move_uploaded_file($_FILES['userfile'][
$file = "$filename" . "$extension" ;
$sql = "UPDATE UserTable SET Filename=\"$file\" WHERE Id='$mpage->IdNum'" ;
$svr->DoQuery($sql);
echo "SUCCESS! You have uploaded your personal image, which will now be displayed on your personal homepage. Now just close this window, and resume editing your profile.";
$mpage->ClosePage();
}
else {
print "Possible file upload attack! You have been reported.";
}
$mpage->ClosePage();
}
Obviously I changed a couple things prior posting this code, but just for security of my site... Now... here's the HTML:
< form enctype="multipart/form-data" action="../members/setupimage.php" method=" post" >
< h3 >Upload A Photo< /h3 >
You are permitted one file that will be uploaded to our servers. It is required to be either a .jpg file or a .gif file, and required to be a real photo of you. Images that do not follow these restrictions will be deleted, and your account subject to deletion.
< input type="hidden" name="MAX_FILE_SIZE" value="100000000" >
Upload Now: < input name="userfile" type="file" >
< input type="submit" name="submit" value=" upload file" >
< /form >
Now, after a bit more probing on DeviantArt, I found out a possible reason it's not uploading in some browsers:
The problem is the browser, moreover the way in which the browser accesses and sends data.
PHP can only recieve uploads from RFC-1867 compliant browsers, such as Netscape or Internet Explorer. (I'm pretty sure that Opera also works fine).
Can someone PLEASE help me with a solution? It's driving me nuts!
-Shade
