您好,我有一个未定义的索引:文件错误,这里说$fileName
,$fileTmpName
,$fileSize
,$fileError
,$fleType
是问题。 / p>
if(isset($_POST['pic_submit'])) //if UPLOAD is clicked
{
$id = $_SESSION['user_id'];
$fileName= $_FILES['file']['name'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileType = $_FILES['file']['type'];
var_dump($fileName);
$fileExt = explode('.', $fileName);
$target_dir = "/images/";
$target_file = $target_dir.$fileName;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
$allowed = array('jpg', 'jpeg', 'png', 'pdf', 'gif');
//if (in_array($fileActualExt, $allowed))
//{
if(isset($fileName))
{
$fileNameNew = uniqid('', true).".".$imageFileType;
$fileDestination = '../images/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
}
}
答案 0 :(得分:1)
只需确保所有内容都设置在主要if
内部即可。 isset
具有可变长度,因此您可以确保在进入循环之前已设置所有条件。
只要做:
if(isset($_POST['pic_submit'], $_FILES['file'])) //if UPLOAD is clicked
应该剪掉它。