pdheady@comcast.net says...[color=blue]
> 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[/color]
No, it's not wrong. It's just the unique temporary name PHP gives to
the temporary copy of the file. The file name attribute is
independently available to you, just not there. Try this:
<?php
if (!isset($infile)) {
echo '
<form action="'.$PHP_SELF.'" ENCTYPE="multipart/form-data"
method=post>
<input type=file name=infile><br>
<input type=submit>
</form>
';
} else {
echo '
File Name:'.$infile_name.' is '.$infile_size.' bytes in size.
';
}
?>
Note the name of the file ($infile) in the form and the use of the
system-generated variables $infile_name and $infile_size.
Not that I'd ever use that approach. For starters, I'd want to rename
the file to a unique value, something like a database record number.
[color=blue]
> } elseif (!preg_match("/(gif|peg|jpg|bmp|png)$/",$ext)) {[/color]
And I'd never trust end-user input to be that correct. Mac users among
others aren't likely to bother with file name extensions at all.
Use the in-built image functions to get the definitive image type.
$imagestats=getImageSize($infile);
if ($imagestats[2]=1) {
copy ($infile, "images/user1.gif");
} elseif ($imagestats[2]=2) {
copy ($infile, "images/user1.jpg");
} elseif ($imagestats[2]=3) {
copy ($infile, "images/user1.png");
} elseif ($imagestats[2]=6) {
copy ($infile, "images/user1.bmp");
} elseif ($imagestats[2]=7) {
copy ($infile, "images/user1.tiff");
} elseif ($imagestats[2]=9) {
copy ($infile, "images/user1.tiff");
} else {
echo '
Sorry user1, supplied file is not a supported image type!
';
}
Cheers,
Geoff M