I've got a script that lets a user upload photos to a directory. This script works great on my Mac OS X machine, but fails on a Windows 98 machine.
This chunk of code checks the upload and if it's valid, moves it into the directory.
if ($_FILES['newfile']['tmp_name']) {
$showid = $_POST['showid'];
$upfile = $_POST['imgdir'] . "/" . $_FILES['newfile']['name'];
$slideresult = mysql_query("SELECT * FROM slideshowimages WHERE showid=$showid AND filename='" . $_FILES['newfile']['name'] . "'", $db);
if (mysql_num_rows($slideresult) != 0) {
$error["filename"] = "There is already a file with that name in this slideshow!";
} elseif ($_FILES['newfile']['size'] == 0) {
$error["filename"] = "This file has a size of zero!";
} elseif (!preg_match('/^[A-Za-z0-9_-]{1,24}\.(jpg|JPG)$/', $_FILES['newfile']['name'])) {
$error["filename"] = "File name can only contain A-Z, a-z, 0-9, ~, - (hyphen) and _ (underscore),<br>and must end with \".jpg\" or \".JPG\"";
} elseif ($_FILES['newfile']['type'] != "image/jpeg") {
$error["filename"] = "The file needs to be a JPEG!";
} elseif (!is_uploaded_file($_FILES['newfile']['tmp_name'])) {
$error["filename"] = "Warning: possible file upload attack!";
} elseif (!copy($_FILES['newfile']['tmp_name'], $upfile)) {
$error["filename"] = "Server error: Could not move file into directory";
}
}
On the Win98 machine, I get the error "The file needs to be a JPEG!", which suggests it's not type "image/jpeg".
The file is chosen for uploading using a "file" type form field. The form includes enctype="multipart/form-data" in the opening <form> tag.
On the Mac, when I click the "Browse" button and choose the file, the field that displays the filename says "myfile.jpg", but on the Windows machine it says "C:\Documents\Testimages\myfile.jpg" - if that might be related to the problem.
Obviously I need to add/change something to accommodate Windows users - any suggestions?