Hello. I am working on a rather large form for my work that accepts, among
other things, 2 images, one smaller one 65 x 93 pixels, and a larger one 105
x 150 pixels, both in JPG format. Let me run through the whole process,
showing my code.
I use simple, standard HTML for the form:
<input type="file" name="thumbImage" size="15">
<input type="file" name="fullImage" size="15">
I check the $_FILES array to make sure the server uploads the images:
array(2) {
["thumbImage"]=>
array(5) {
["name"]=>
string(15) "DAK01_thumb.jpg"
["type"]=>
string(11) "image/pjpeg"
["tmp_name"]=>
string(14) "/tmp/phpXxmX1s"
["error"]=>
int(0)
["size"]=>
int(7161)
}
["fullImage"]=>
array(5) {
["name"]=>
string(14) "DAK01_full.jpg"
["type"]=>
string(11) "image/pjpeg"
["tmp_name"]=>
string(14) "/tmp/php05LOkc"
["error"]=>
int(0)
["size"]=>
int(12235)
}
}
I do the following error checking for various things:
// Small Thumbnail Image
if (trim($_FILES["thumbImage"]["tmp_name"])) {
if ($_FILES["thumbImage"]["size"] > 10240) {
$formVars["results"] .= "The small photo must be 10240 bytes or less<br
/>";
}
if ($_FILES["thumbImage"]["type"] != "image/pjpeg" &&
$_FILES["thumbImage"]["type"] != "image/jpeg") {
$formVars["results"] .= "The small photo must be in .jpg format<br />";
}
$imgSize = getimagesize($_FILES["thumbImage"]["tmp_name"]);
if ($imgSize[0] > 65) {
$formVars["results"] .= "The small photo must be 65 pixels wide or
less<br />";
}
}
// Full Image
if (trim($_FILES["fullImage"]["tmp_name"])) {
if ($_FILES["fullImage"]["size"] > 20480) {
$formVars["results"] .= "The large photo must be 20480 bytes or less<br
/>";
}
if ($_FILES["fullImage"]["type"] != "image/pjpeg" &&
$_FILES["fullImage"]["type"] != "image/jpeg") {
$formVars["results"] .= "The large photo must be in .jpg format<br />";
}
$imgSize = getimagesize($_FILES["fullImage"]["tmp_name"]);
if ($imgSize[0] > 105) {
$formVars["results"] .= "The large photo must be 105 pixels wide or
less<br />";
}
}
Then, I move the temp image files:
// Copy image to $GLOBALS["dvdimgpath"].$_POST["gameId"]."_[thumb/full].jpg"
$thumbPath = $GLOBALS["dvdimgpath"].$_POST["gameId"]."_thumb.jpg";
$fullPath = $GLOBALS["dvdimgpath"].$_POST["gameId"]."_full.jpg";
echo "Thumb image uploaded to ".$thumbPath."<br />\n";
if (!move_uploaded_file($_FILES["thumbImage"]["tmp_name"], $thumbPath)) {
$formVars["results"] .= "Image file could not moved to the images dir.
Please try again";
}
echo "Full image uploaded to ".$fullPath."<br />\n";
if (!move_uploaded_file($_FILES["fullImage"]["tmp_name"], $fullPath)) {
$formVars["results"] .= "Image file could not moved to the images dir.
Please try again";
}
Everything works fine, except that the images are simply not there when we
go look for them. The best explanation I can come up with is that they are
not moved, but I have no idea why. I've done this with no problem on my
personal site. Is it a problem with the move_uploaded_file function? Any
ideas?
Thanks!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php