【发布时间】:2015-08-09 14:51:49
【问题描述】:
在你说这是重复之前,我会说我尝试了我在互联网上可以找到的所有东西,但没有任何效果。我正在尝试上传图片,但它给了我这个错误:
未定义索引:图片
<?php
$target_dir = "images/";
$target_file = $target_dir . basename($_FILES["image"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["image"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
if ($uploadOk == 0) {
die(mysqli_error($dbc));
echo "Sorry, your file was not uploaded.";
} else {
if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
<form action="SchimbareImagine.blade.php" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label>Poster:</label>
<div class="col-lg-10">
<input id="input-5" type="file" name = "image" >
</div>
</div>
</div>
<button name = "submit" type="submit" id = "submit" >Submit</button>
</form>
有谁知道我该如何解决这个问题?
【问题讨论】:
-
在尝试使用之前,只需使用
isset()检查$_FILES['image']是否存在。 -
现在它说:未定义变量:target_file
-
你能把修改后的代码贴出来吗?