If you're willing to help a little more...
I've been playing around with this - and I'm very new to PHP... so this coding is a little ridiculous. I'm sure that it could be a lot more simple, but I'm bad at this - I'm surprised it's working out as well as it is.
The code below gives all the correct error messages (file is not an image, file size is zero, or the field was left blank, so it skips over that image - if that makes sense).
Anyway, all of this is working except for the fact that the file still uploads even if it's not an image... I want only images to be allowed to copy over.
Here's the code, and my solution (that's not working):
if ($filesize1 + $filesize2 + $filesize3 + $filesize4 + $filesize5 == 0) {
echo "Error: no files attached";
exit();
}
else {
echo "<h2>Thank you! We have recieved the images listed below.</h2>";
echo "<p>Pending a review, we will post this on the photos page.<br><span style='font-size:.85em;'><em>Please note that we may not include every image sent to us.</em></span></p><br>";
if ($HTTP_POST_FILES['ufile']['tmp_name'][0] != '') {
if ($isimage1 && $filesize1 > 0) {
echo "<p>";
echo "<b>".$HTTP_POST_FILES['ufile']['name'][0]."</b><br>";
echo "<img src=\"$path1\">";
echo "</p>";
}
else {
if (!$filesize1) {echo "There was an error with the first image. Please try it again.";}
else {echo "Error with the first upload: only images are allowed";}
}
}
if ($HTTP_POST_FILES['ufile']['tmp_name'][1] != '') {
if ($isimage2 && $filesize2 > 0) {
echo "<p>";
echo "<b>".$HTTP_POST_FILES['ufile']['name'][1]."</b><br>";
echo "<img src=\"$path2\">";
echo "</p>";
}
else {
if (!$filesize2) {echo "There was an error with the second image. Please try it again.";}
else {echo "Error with the second upload: only images are allowed";}
}
}
if ($HTTP_POST_FILES['ufile']['tmp_name'][2] != '') {
if ($isimage3 && $filesize3 > 0) {
echo "<p>";
echo "<b>".$HTTP_POST_FILES['ufile']['name'][2]."</b><br>";
echo "<img src=\"$path3\">";
echo "</p>";
}
else {
if (!$filesize3) {echo "There was an error with the third image. Please try it again.";}
else {echo "Error with the third upload: only images are allowed";}
}
}
if ($HTTP_POST_FILES['ufile']['tmp_name'][3] != '') {
if ($isimage4 && $filesize4 > 0) {
echo "<p>";
echo "<b>".$HTTP_POST_FILES['ufile']['name'][3]."</b><br>";
echo "<img src=\"$path4\">";
echo "</p>";
}
else {
if (!$filesize4) {echo "There was an error with the fourth image. Please try it again.";}
else {echo "Error with the fourth upload: only images are allowed";}
}
}
if ($HTTP_POST_FILES['ufile']['tmp_name'][4] != '') {
if ($isimage5 && $filesize5 > 0) {
echo "<p>";
echo "<b>".$HTTP_POST_FILES['ufile']['name'][4]."</b><br>";
echo "<img src=\"$path5\">";
echo "</p>";
}
else {
if (!$filesize5) {echo "There was an error with the fifth image. Please try it again.";}
else {echo "Error with the fifth upload: only images are allowed";}
}
}
}
?>
Sorry - the coding is a little crazy (and probably really stupid)
Anyway, I thought that doing this would work:
if ($isimage1) {copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);}
if ($isimage2) {copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);}
if ($isimage3) {copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3);}
if ($isimage4) {copy($HTTP_POST_FILES['ufile']['tmp_name'][3], $path4);}
if ($isimage5) {copy($HTTP_POST_FILES['ufile']['tmp_name'][4], $path5);}
But it only produces errors... why would this not work? (I know that again, it's probably a dumb question, but I'm trying to learn)
Thanks again for any help. I really appreciate it.
Bookmarks