a.php只会
<form action="pic.php" method="post" enctype="multipart/form-data">
<input type="file" name="pic">
<input type="submit">
</form>
pic.php
print $_FILES; // Returns Array
if ($_FILES['pic']['name']){
$pic_path = '/pictures/' . $_FILES['pic']['name'];
}
我正在尝试将图片与其他数据一起上传,但是由于索引不存在而导致错误... undefined index: pic
并且不知道原因。
答案 0 :(得分:0)
我猜这个错误只会在不上传文件时出现,对吗?
您需要先检查是否已使用is_uploaded_file()
上传了任何内容,请参阅http://php.net/manual/en/function.is-uploaded-file.php
编辑:请参阅此处获取教程:http://php.net/manual/en/features.file-upload.post-method.php