image upload

Tjekker ikke om billedet er over 1 MB. Men er billedet over, er var_dump INT(0) Mindre billeder give INT(tal) Prøver jeg med et på 3,07 MB (3.227.516 byte) Så er INT(0) og den giver heller ikke error med billede over 1 MB. Hvorfor?
 avatar
Esbjerg82
php
2 years ago
2.8 kB
11
Indexable
														
<?php
if (isset($_POST['UpdateMembers'])) {
	
			$id = $_POST['id'];

			$files = $_FILES['file'];
			$dir = "../members/";
			$dims = 900;
			$watermarkPath = "watermark.png";
			$extAllowed = ["jpg", "jpeg", "png", "gif"];

			define('KB', 1024);
			define('MB', 1048576);
			define('GB', 1073741824);
			define('TB', 1099511627776);
			
			
			$margin_right = 0;
			$margin_bottom = 0;
			$watermarkSize = ($dims * 15) / 90;
			$watermarkImg = imagescale(imagecreatefromstring(file_get_contents($watermarkPath)), $watermarkSize, $watermarkSize);
			$sx = imagesx($watermarkImg);
			$sy = imagesy($watermarkImg);
	
			$fileOrignal = pathinfo($files['name'], PATHINFO_FILENAME) . " - " . "blahblah.dk_" . time() ."." . pathinfo($files['name'], PATHINFO_EXTENSION);
			$fileType = strtolower(pathinfo($files['name'], PATHINFO_EXTENSION));
			$fileTmpName = $files['tmp_name'];
			$fileError = $files['error'];
			$fileSize = $files['size'];
			$path = $dir . $fileOrignal;

			$exif = @exif_read_data($fileTmpName);
			$image = imagecreatefromstring(file_get_contents($fileTmpName));
			$imageResize = imagescale($image, $dims, $dims);

			if ($exif && isset($exif['Orientation'])) {
				switch ($exif['Orientation']) {
					case 3:
						$imageResize = imagerotate($imageResize, 180, 0);
						break;
					case 6:
						$imageResize = imagerotate($imageResize, -90, 0);
						break;
					case 8:
						$imageResize = imagerotate($imageResize, 90, 0);
						break;
				}
			}

			switch ($fileType) {
				case $fileType == "png":
					//imagealphablending($imageResize, false);
					imagesavealpha($imageResize, true);
					imagepng($imageResize, $path);
					break;
				case $fileType == "jpg" || $fileType == "jpeg":
					imagejpeg($imageResize, $path);
					break;
				case $fileType == "gif":
					imagegif($imageResize, $path);
					break;
			}
            
			imagecopy($imageResize, $watermarkImg, imagesx($imageResize) - $sx - $margin_right, imagesy($imageResize) - $sy - $margin_bottom, 0, 0, imagesx($watermarkImg), imagesy($watermarkImg));
			imagepng($imageResize, $path);

			imagedestroy($image);
			imagedestroy($imageResize);
			
				var_dump($fileSize);
			
			
			if ($fileSize > 1 * MB) {
			$_SESSION['addMembersError'] = true;
			$_SESSION['addMem_imagebig'] = true;
			include ("msgInfo.php");
			} else {
			
			if (in_array($fileType, $extAllowed)) {

	
		    move_uploaded_file($fileOrignal, "../members/");
			 
			$sql1 = "UPDATE `members` SET 
			profilepic      ='".$fileOrignal."'
			WHERE id='".$_POST['id']."'";
			$resdel1 = mysqli_query($dm, $sql1);
			
			} else {
			$_SESSION['not_allowed'] = true;
			}
			}

			imagedestroy($watermarkImg);
			
}
?>