<?php |
<?php |
|
|
include("common.inc.php"); |
include("common.inc.php"); |
include_header("confirmUpload"); |
include_header("confirmUpload"); |
$error = false; |
$error = false; |
|
|
if (!isset($_FILES['userfile'])) { |
if (!isset($_FILES['userfile'])) { |
echo 'No file was uploaded. You should start from the <a href="upload.php">upload page</a>'; |
echo 'No file was uploaded. You should start from the <a href="upload.php">upload page</a>'; |
$error = true; |
$error = true; |
} else { |
} else { |
$imageinfo = getimagesize($_FILES['userfile']['tmp_name']); |
$imageinfo = getimagesize($_FILES['userfile']['tmp_name']); |
$source_image_type = $imageinfo['mime']; |
$source_image_type = $imageinfo['mime']; |
$source_image_width = $imageinfo[0]; |
$source_image_width = $imageinfo[0]; |
$source_image_height = $imageinfo[1]; |
$source_image_height = $imageinfo[1]; |
} |
} |
|
|
if($error == false && ($source_image_type != 'image/png' && $source_image_type != 'image/jpeg')) { |
if ($error == false && ($source_image_type != 'image/png' && $source_image_type != 'image/jpeg')) { |
echo "Sorry, we only accept PNG and JPEG images. Your image was of type '$source_image_type'.<br>"; |
echo "Sorry, we only accept PNG and JPEG images. Your image was of type '$source_image_type'.<br>"; |
$error = true; |
$error = true; |
} |
} |
if($error == false && ($source_image_width < MIN_IMAGE_SIZE || $source_image_height < MIN_IMAGE_SIZE)) { |
if ($error == false && ($source_image_width < MIN_IMAGE_SIZE || $source_image_height < MIN_IMAGE_SIZE || $source_image_width != $source_image_height)) { |
echo "Sorry, we only accept images larger than ".MIN_IMAGE_SIZE." pixels. Your image was $source_image_width x $source_image_height pixels big. <br>"; |
echo "Sorry, your image wasn't big enough. In order to ensure that John's calendar looks super-beautiful, we only accept images that are 1000 px or larger and are squares. Your image was $source_image_width x $source_image_height pixels big. <br>"; |
$error = true; |
$error = true; |
} |
} |
|
$hash = md5_file($_FILES['userfile']['tmp_name']); |
if($error == false && ($source_image_width != $source_image_height)) { |
if ($error == false && sizeof(glob(DATA_DIR."*".$hash."*")) > 0) { |
echo "Sorry, we only accept images that are exactly square (the height is the same as the width). Your image was $source_image_width x $source_image_height pixels big. <br>"; |
echo "Sorry, we already have an image identical to this one.<br>"; |
$error = true; |
$error = true; |
} |
} |
|
|
if (!$error) { |
if (!$error) { |
$fileExtension = ($source_image_type == 'image/png' ? ".png" : ".jpg"); |
$fileExtension = ($source_image_type == 'image/png' ? ".png" : ".jpg"); |
$fileDate = getNextAvailableDate(); |
$fileDate = getNextAvailableDate(); |
echo "Uploaded file meets all necessary requirements, next available date is $fileDate <br>"; |
//echo "Uploaded file meets all necessary requirements, next available date is $fileDate <br>"; |
$uploaddir = '/var/spool/uploads/'; # Outside of web root |
$uploadfile = DATA_DIR . $fileDate . ".".$hash. $fileExtension; |
$uploadfile = DATA_DIR . $fileDate . $fileExtension; |
if (file_exists($uploadfile)) { |
if (file_exists($uploadfile)) { |
echo "Oh no! A file for $fileDate already exists! Please retry in a moment<br>"; |
echo "Oh no! A file for $fileDate already exists! Please retry in a moment<br>"; |
} else { |
} else { |
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { |
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { |
echo "Yay! Your image has been added as $fileDate. Click <A href='index.php'>here</a> to go back to the site.\n<br>"; |
echo "File was successfully uploaded.\n<br>"; |
} else { |
} else { |
echo "File uploading failed.\n<br>"; |
echo "File uploading failed.\n<br>"; |
} |
} |
} |
} |
|
} |
} |
include_footer(); |
include_footer(); |
?> |
?> |