1
你好,我嘗試閱讀類似的問題,並不能解決問題。php move_uploaded_file()不能上傳視頻
我成功上傳圖片,但無法將視頻上傳到我的服務器,現在我正在使用XAMPP在本地進行測試。
我已經給寫作,閱讀文件夾的權限,它仍然不動的文件,當然還有我的PHP文件是在同一文件夾作爲我在這種情況下,目的地「./」
預先感謝誰試圖幫助。
這是我的代碼。
<?php
$target_dir = "./";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" && $imageFileType != "mkv" && $imageFileType != "mp4") {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
這是更好的做法有'$ TARGETDIR = __DIR __。DIRECTORY_SEPARATOR'而不是'/'這取決於當前的工作目錄(可能不是腳本目錄) – apokryfos