Я пытаюсь добавить фотографии в свою форму, но не могу заставить ее работать. Я просмотрел все ресурсы, которые смог найти, но не смог решить эту проблему. Моя папка доступна для записи, существует. Синтаксис move_uploaded_file (tmpfileName, fileDestination) тоже правильный.
Вот мой код:
if($_FILES['thread_image']['name']!=""){
$fileExtBreak = explode('.', $_FILES['thread_image']['name']);
$fileExt = strtolower(end($fileExtBreak));
$allowed = array('jpg','jpeg','png','pdf');
if(in_array($fileExt, $allowed)){
$_SESSION['errors'] = $errors;
if($_FILES['thread_image']['error'] > 0){
$errors[] = 'Something went wrong when trying to upload your image.';
$_SESSION['errors'] = $errors;
header("Location:topic.php?id=". $_GET['id'] ."");
}else{
if($_FILES['thread_image']['size']>=10000000){
$errors[] = 'The file you are trying to upload is too big';
$_SESSION['errors'] = $errors;
header("Location:topic.php?id=". $_GET['id'] ."");
}else{
if(!is_dir('images')){
$errors[]='This shit doesn\'t exist';
}else if(!is_writable('images')){
$errors[]='This shit isn\'t writable';
}else{
$errors[]='It exists and should work!!!!';
}
$fileName = $date.'.'.$fileExt;
$filePath = 'images/'.$fileName;
$errors[]=$_FILES['thread_image']['tmp_name'];
$errors[]=$fileName;
$errors[]=$filePath;
if(move_uploaded_file($_FILES['thread_image']['tmp_name'], $filePath)){
$errors[]="success";
}else{
$errors[]="didn't work, sorry";
}
$errors[]=mysqli_error($link);
$_SESSION['errors'] = $errors;
$stmt = $link->prepare("UPDATE threads set thread_has_image='1' WHERE thread_date=?");
$stmt->bind_param("s",$date);
$result=$stmt->execute();
}
}
}else{
$errors[] = "You cannot upload files with that type";
$_SESSION['errors'] = $errors;
header("Location:topic.php?id=". $_GET['id'] ."");
}
}
А вот что он выплевывает:
1) проверяет, существует ли папка, 2) выплевывает временное имя файла 3) выплевывает созданное мной имя файла, 4) выплевывает созданный мной пункт назначения 5) проверяет, работал ли move_uploaded_file
![1)checks whether the folder exists, 2)spits out the temporary file name 3)spits out my file name I created, 4)spits out the file Destination I created 5)checks whether move_uploaded_file worked](https://i.stack.imgur.com/3RckU.png)
Вот моя форма:
<form class="makerContainer" method="post" enctype="multipart/form-data" action=<?php echo '"threadMaker_handler.php?id=' . $_GET[ 'id'] . '"'; ?>>
<fieldset class="good">
<div class="makerForm">
Thread Title:
<input type="text" class="title" title="ThreadTitle" name="thread_title" <?php echo 'value="' . $name . '"'; ?>>
</div>
<div class="makerForm">
Thread Description:
<textarea class="description" rows="8" cols="100" name="thread"><?php echo '' . $thread . ''; ?></textarea>
<div class="submitPanel">
<input type="file" name="thread_image"/>
<input type="submit" class="button buttonModal buttonColor" value="+ Create Thread">
</div>
</div>
</fieldset>
</form>