我的代碼:與PHP的問題上傳
if(isset($_FILES['image'])){
$allowedExts = array('jpg', 'gif', 'png');
$extension = end(explode('.', $_FILES['image']['name']));
if(in_array($extension, $allowedExts)){
if($_FILES['image']['size'] < 50000){
if ($_FILES['image']['error'] > 0){
$uploaderror = $_FILES['image']['error'];
}else{
$uploaderror = 'FALLBACK ERROR';
if(file_exists('..images/'.$_FILES['image']['name'])){
$uploaderror = 'The file <strong>'.$_FILES['image']['name'].'</strong> already exists in the images directory.';
}else{
move_uploaded_file($_FILES['file']['tmp_name'], '..images/'.$_FILES['file']['name']);
$uploadsuccess = $_FILES['file']['name'];
}
}
}else{$uploaderror = 'The image is too large.';}
}else{$uploaderror = 'Only images (.jpg, .png, and .gif) are allowed.';}
}else{$uploaderror = 'No attempt';}
輸出: $uploaderror
回報FALLBACK ERROR
和$uploadsuccess
沒有設置。該文件沒有出現在指定的目錄中,我無法在服務器上找到它。請告訴我我做錯了什麼。謝謝!
哇,這是一些嘈雜的代碼。 – BastiBen
你的表單是什麼樣的?在某些地方你使用'$ _FILES ['image']'和其他你使用'$ _FILES ['file']' –
這種格式是錯誤的:''..images /'.$_ FILES ['file'] ['' name']'你丟失''''''''''''後面的'''' –