- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
June 6, 2016 at 5:06 am #242545
cscodismith
ParticipantI have a function on my website that is not yet released that admins will use to make posts on the homepage. Part of this function involves uploading an image and there is currently no check for this but would like to make it so that it will check to make sure that they are only uploading images that are either one of the following resolutions:
1920px width;1080px height 1280px width;720px height
I am not to sure how to check this but my current code for uploading images looks like the following:
<?php function uploadImage() { $target_dir = "uploads/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); // Check if image file is a actual image or fake image if(isset($_POST["submit"])) { $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if($check !== false) { $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } } // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } // Check file size if ($_FILES["fileToUpload"]["size"] > 500000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") { echo "Sorry, only JPG, JPEG, & PNG files are allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { return $target_file; } else { echo "Sorry, there was an error uploading your file."; } }
June 6, 2016 at 7:14 am #242557Beverleyh
ParticipantUntested but it might work if you change
if($check !== false) {
to
if ( ($check !== false) && ($check[0] == 1920 && $check[1] == 1080) || ($check[0] == 1280 && $check[1] == 720) ) {
June 6, 2016 at 7:16 am #242558I.m.learning
ParticipantTake a look at this page
http://codular.com/php-file-uploadsJune 6, 2016 at 9:18 pm #242586cscodismith
ParticipantUnfortunately this doesn’t check it the way I would like. It still allows any size image to be uploaded :(
-
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘Back End’ is closed to new topics and replies.