Я не уверен, почему загружаемый файл вообще не распознается. Форма HTML находится в отдельном файле от PHP.
Я убедился, что file_uploads включен из моей конфигурации php .ini.
HTML:
<div class="col-md-6 col-xs-6">
<div class="form-group">
<label class="custom-file-label" for="customFile">Verification Photo</label>
<input type="file" class="custom-file-input" id="verphoto" name="verphoto" required>
<small class="form-text text-muted">Only supports JPG. Max size : 5mb</small>
<div class="help-block with-errors"></div>
</div>
</div>
</div>
PHP:
//check file type
$target_dir = "../z2tools/userimages/";
$target_file = $target_dir . basename($_FILES["verphoto"]["name"]);
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
$check = getimagesize($_FILES["verphoto"]["tmp_name"]);
if($check !== false) {
//check file size
if ($_FILES["verphoto"]["size"] < 5000000) {
//resize
$file_tmp_name = $_FILES["verphoto"]["tmp_name"];
$ratio = $width/$height;
if($ratio > 1) {
$new_width = 350;
$new_height = 350/$ratio;
}
else {
$new_width = 350*$ratio;
$new_height = 350;
}
// Rename file
$temp = explode('.', $target_file);
$newfilename = $usernick.'.'.end($temp);
// Upload image
if(move_uploaded_file($file_tmp_name , $target_dir.$newfilename)) {
$src = imagecreatefromstring(file_get_contents($target_dir.$newfilename));
$dst = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagedestroy($src);
imagepng($dst, $target_dir.$newfilename);
imagedestroy($dst);
//upload success
echo '<p><img class="iconsize" src="image/mail.gif"/></p>';
echo '<p>upload success.</p>';
}
else {
//upload failed
echo '<p><img class="iconsize" src="image/errors.png"/></p>';
echo '<p>upload failed.</p>';
}
}
else {
//invalid file size
echo '<p><img class="iconsize" src="image/errors.png"/></p>';
echo '<p>Invalid file size.</p>';
}
}
else {
//invalid file type
echo '<p><img class="iconsize" src="image/errors.png"/></p>';
echo '<p>Invalid file type uploaded.</p>';
}
И результат всегда verphoto is undefined
.
Любое предложение приветствуется. Заранее спасибо.