How to make it in the code so that the width was changed before loading, for example, 400px was made

code:

$unikod = substr(md5(microtime(true)), 0, 20); $uploaddir = 'images/user/'; $file = $uploaddir . $unikod.".jpg"; $filenew = $uploaddir . $unikod.".jpg"; $ext = substr($_FILES['uploadfile']['name'],strpos($_FILES['uploadfile']['name'],'.'),strlen($_FILES['uploadfile']['name'])-1); $filetypes = array('.jpg','.gif','.bmp','.png','.JPG','.BMP','.GIF','.PNG','.jpeg','.JPEG'); if(!in_array($ext,$filetypes)){ echo "<p>Данный формат файлов не поддерживается</p>"; } else{ if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $filenew)) { echo $filenew; } else { echo "error"; } 
  • After loading but before saving? - Solid
  • Yes, somehow, just not to create an extra file, for example, the file was loaded, its script changed in size and overwritten. I just can't figure out how to do it ... - Alexander Sizintsev

1 answer 1

 $image = imagecreatefromjpeg($_FILES['uploadfile']['tmp_name']); $new_image = imagecreatetruecolor(400, 400); imagecopyresampled($new_image, $image, 0, 0, 0, 0, 400, 400, imagesx($image), imagesy($image)); imagejpeg($new_image,$filename,75); 
  • where to insert it in the code? - Alexander Sizintsev
  • I did not check, I wrote it without a word, you can insert it instead of move_uploaded_file. And for png and gif there will be other functions. - Solid