I need to upload 3 images and resize them as part of a forme but for some reason, the images does not end up in the server directory. What am i missing?
The fille array looks like this:
Array
(
[file1] => Array
(
[name] => s_casafolio.png
[type] => image/png
[tmp_name] => /tmp/phpENy7j4
[error] => 0
[size] => 2047496
)
[file2] => Array
(
[name] => lawjournal.png
[type] => image/png
[tmp_name] => /tmp/phpT0fu1Y
[error] => 0
[size] => 1139448
)
[file3] => Array
(
[name] => s_mdj_2.png
[type] => image/png
[tmp_name] => /tmp/phpUsRk6W
[error] => 0
[size] => 792873
)
)
And my processing looks like this:
<?php
$tmp = md5(md5(date("YmdHis")));
$img_quality = 70;
$maxDim = 700;
$dest_folder = "/home/user/public_html/userfiles/inscription_designer/";
$valid_mime_types_images = array(
"image/gif",
"image/png",
"image/jpeg",
"image/pjpeg",
);
if (in_array($_FILES["file1"]["type"], $valid_mime_types_images)) {
$ext = pathinfo($_FILES['file1']['name'], PATHINFO_EXTENSION);
$dest_file = $dest_folder.$tmp.'1.'.$ext;
$fn = $_FILES['file1']['tmp_name'];
$size = getimagesize($fn);
$ratio = $size[0]/$size[1]; // width/height
if( $ratio > 1) {
$width = $maxDim;
$height = $maxDim/$ratio;
}
else {
$width = $maxDim*$ratio;
$height = $maxDim;
}
$src = imagecreatefromstring(file_get_contents($fn));
$dst = imagecreatetruecolor($width,$height);
imagecopyresampled($dst,$src,0,0,0,0,$width,$height,$size[0],$size[1]);
imagedestroy($src);
imagepng($dst,$dest_file); // adjust format as needed
imagedestroy($dst);
}else{
$err .= "- Image 1 est invalide.<br />";
}
if (in_array($_FILES["file2"]["type"], $valid_mime_types_images)) {
$ext = pathinfo($_FILES['file2']['name'], PATHINFO_EXTENSION);
$dest_file = $dest_folder.$tmp.'2.'.$ext;
$fn = $_FILES['file2']['tmp_name'];
$size = getimagesize($fn);
$ratio = $size[0]/$size[1]; // width/height
if( $ratio > 1) {
$width = $maxDim;
$height = $maxDim/$ratio;
}
else {
$width = $maxDim*$ratio;
$height = $maxDim;
}
$src = imagecreatefromstring(file_get_contents($fn));
$dst = imagecreatetruecolor($width,$height);
imagecopyresampled($dst,$src,0,0,0,0,$width,$height,$size[0],$size[1]);
imagedestroy($src);
imagepng($dst,$dest_file); // adjust format as needed
imagedestroy($dst);
}else{
$err .= "- Image 2 est invalide.<br />";
}
if (in_array($_FILES["file3"]["type"], $valid_mime_types_images)) {
$ext = pathinfo($_FILES['file3']['name'], PATHINFO_EXTENSION);
$dest_file = $dest_folder.$tmp.'3.'.$ext;
$fn = $_FILES['file3']['tmp_name'];
$size = getimagesize($fn);
$ratio = $size[0]/$size[1]; // width/height
if( $ratio > 1) {
$width = $maxDim;
$height = $maxDim/$ratio;
}
else {
$width = $maxDim*$ratio;
$height = $maxDim;
}
$src = imagecreatefromstring(file_get_contents($fn));
$dst = imagecreatetruecolor($width,$height);
imagecopyresampled($dst,$src,0,0,0,0,$width,$height,$size[0],$size[1]);
imagedestroy($src);
imagepng($dst,$dest_file); // adjust format as needed
imagedestroy($dst);
}else{
$err .= "- Image 3 est invalide.<br />";
}
?>