I have a webpage that uploads a photo picture file to server, but goes
through some error checking before it redirects to the next page. Since I do
not have PHP compiled with mime type support I have checking last 3
characters of filename. Here are my problems:
1) When I set form type to ENCTYPE="multipart/form-data" i can check the
file size correctly and works fine, but then filename and extension are in
some weird format which is binary I believe.
form = 1
Photo: /tmp/phpnDF01W
image_x = 89
image_y = 16
Ext: 01w < this is wrong, should be gif/jpg/etc...
Size: 34326
File: /tmp/phpnDF01W < this is wrong
2) When I omit the above form type and use default, file size function fails
but the extension and filename work correctly. I believe this is because it
is sent in ascii/plain text mode.
Warning: filesize(): Stat failed for C:\\WINDOWS\\Desktop\\sci.psd
(errno=2 - No such file or directory) in
/home/fcl/public_html/free/index3.php on line 30
form = 1
photo = C:\\WINDOWS\\Desktop\\sci.psd
image_x = 66
image_y = 12
Ext: psd
Size: ??????
File = C:\\WINDOWS\\Desktop\\sci.psd
3) I'm also trying to get the file to the server and it's not uploading it.
It's creating the directories but not moving the file up there for me!!
4) Here is code. What is going on? Can I kill 3 birds with one stone here???
I'd rather not recompile PHP. Must I convert $ext from binary to plain
text??
while(list($key, $value) = each($HTTP_GET_VARS)) {
echo "$key = $value<br>";
}
if ($form) {
if ($photo) {
$ext = strtolower(substr($photo, -3));
function fsize($photo) {
return filesize($photo);
}
$size = fsize($photo);
if ($size > 100000) {
$focus = "photo";
$msg = "Your file size exceeds the maximum allowed
upload. Please re-submit or skip this step.";
} elseif (!preg_match("/(gif|peg|jpg|bmp|png)$/",
$ext)) {
$focus = "photo";
$msg = "Invalid file type. Please submit a gif, jpeg,
bmp, or png photo.";
} else {
if ($ltype == "1") { $type = "hotel"; }<-- this all works fine, etc
if ($ltype == "2") { $type = "inn"; }
if ($ltype == "3") { $type = "bandb"; }
if ($ltype == "4") { $type = "resort"; }
$imgdir = "$DOCUMENT_ROOT/lodging/$type"; <-- this all works fine,etc
if (!file_exists($imgdir)) { mkdir($imgdir, 0755); }
$imgdir.= "/$aid";
if (!file_exists($imgdir)) { mkdir($imgdir, 0755); }
move_uploaded_file($photo, "$imgdir/photo1.jpg"); <---this is not
working!!
loc("index4.php?sid=$sid&aid=$aid"); <-- works fine
}}
<form name="form1" method="post"
action="<?=$SCRIPT_NAME?>?sid=<?=$sid?>&aid=<?=$ai d?><ype=<?=$ltype?>"
ENCTYPE="multipart/form data">
<input type="hidden" name="form" value="1">