<?
function getPath() {
global $SCRIPT_FILENAME;
$tmp = split("[/]",$SCRIPT_FILENAME);
$tmp = $tmp[count($tmp)-1];
$tmp = str_replace($tmp,"",$SCRIPT_FILENAME);
return $tmp;
}
function isImage($imageFile) {
// Allow GIF/JPG/PNG files
$isImage = $imageFile[2]<4;
return $isImage;
}
function checkImageSize($imageFile,$imageWidth,$imageHeight) {
if ($imageFile[0]==$imageWidth && $imageFile[1]==$imageHeight) {
return true;
} else {
return false;
}
}
// Allow only image file
if (!$imageFile = @getImageSize($HTTP_POST_FILES["myFile"]["tmp_name"])) {
$errorMessage = "Please upload a valid file";
exit("<html><head><title>An error occured during upload process</title></head><body><script language=\"JavaScript\" type=\"text/javascript\">alert(\"$errorMessage\");parent.imgRollBack(\"$zoneId\")</script></body></html>");
}
// Allow only GIF/JPEG/PNG formats
if (!isImage($imageFile)) {
$errorMessage = "Only GIF, JPEG or PNG files may be uploaded";
exit("<html><head><title>An error occured during upload process</title></head><body><script language=\"JavaScript\" type=\"text/javascript\">alert(\"$errorMessage\");parent.imgRollBack(\"$zoneId\")</script></body></html>");
}
// Check image size
$imageWidth=60; // All images should have a width of 60 pixels
$imageHeight=45; // All images should have an height of 45 pixels
if (!checkImageSize($imageFile,$imageWidth,$imageHeight)) {
$errorMessage = "Only image with a width of 60 pixels and an height of 45 pixels may be uploaded";
exit("<html><head><title>An error occured during upload process</title></head><body><script language=\"JavaScript\" type=\"text/javascript\">alert(\"$errorMessage\");parent.imgRollBack(\"$zoneId\")</script></body></html>");
}
// Check image weight
$imageWeight=5000; // Images should be less than 5k
if ($HTTP_POST_FILES["myFile"]["size"]>=$imageWeight) {
$errorMessage = "Only image with a weight under 5k may be uploaded";
exit("<html><head><title>An error occured during upload process</title></head><body><script language=\"JavaScript\" type=\"text/javascript\">alert(\"$errorMessage\");parent.imgRollBack(\"$zoneId\")</script></body></html>");
}
// Save uploaded image
$savePath = getPath() . "tmp/" . $HTTP_POST_FILES["myFile"]["name"];
$isValidUpload = move_uploaded_file ($HTTP_POST_FILES["myFile"]["tmp_name"], $savePath);
if ($isValidUpload) {
// Valid upload, display preview
print "
<html>
<head><title>Valid upload, display preview</title></head>
<body>
<script language=\"JavaScript\" type=\"text/javascript\">
parent.imgPreview(\"$zoneId\",\"tmp/".$HTTP_POST_FILES["myFile"]["name"]."\")
</script>
</body>
</html>";
} else {
// Invalid upload
$errorMessage = "Invalid upload";
exit("<html><head><title>An error occured during upload process</title></head><body><script language=\"JavaScript\" type=\"text/javascript\">alert(\"$errorMessage\");parent.imgRollBack(\"$zoneId\")</script></body></html>");
}
?>