Hi guys,
I have managed to code a file that uploads a file, resizes it to 100 x 100 px, and then generates a random number and renames the image (so i do not get images over writing each other), what i am stuck on is trying to block uploads that are over 200kb, and if there is no file to upload (as there will be no need sometimes to upload a file) to skip the code all together in order to process some more code i got going on after this piece, can anyone help! i have looked around various websites and am just absoulty stuck on this!
Any help is much appriciated
The Code:
<?php
if(isset($_POST['submit'])){
if (isset ($_FILES['file'])){
imagename = $_FILES['file']['name'];
$random_digit=rand(0000,9999);
$new_file_name=$random_digit.$imagename;
$source = $_FILES['file']['tmp_name'];
$target = "Articleimages/".$new_file_name;
move_uploaded_file($source, $target);
$imagepath = $new_file_name;
$save = "Articleimages/" . $imagepath;
$file = "Articleimages/" . $imagepath;
list($width, $height) = getimagesize($file) ;
$modwidth = 100;
$diff = $width / $modwidth;
$modheight = 100;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
$save = "Articleimages/Thumbs/" . $imagepath;
$file = "Articleimages/" . $imagepath;
list($width, $height) = getimagesize($file) ;
$modwidth = 100;
$diff = $width / $modwidth;
$modheight = 100;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
}
}
}
?>
Cheers
Jay!