我想上傳一個文件並將其保存在一個文件夾中。它打印:成功,但該文件不在目標文件夾中。我是否給予任何類型的權限?我如何給他們?另外我該如何指定目標文件夾路徑,即我使用\或/?上傳並保存在php文件
<?php
if(isset($_FILES['image'])){
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size = $_FILES['image']['size'];
$file_tmp = $_FILES['image']['tmp_name'];
$file_type = $_FILES['image']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
$expensions= array("jpeg","jpg","png");
if(in_array($file_ext,$expensions)=== false){
echo "1";
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size > 2097152) {
echo "2";
$errors[]='File size must be excately 2 MB';
}
if(empty($errors)==true) {
echo "Sarang";
move_uploaded_file($file_tmp,"/uploads".$file_name);
echo "Success";
}else{
print_r($errors);
}
}
?>
<html>
<body>
<form action = "" method = "POST" enctype = "multipart/form-data">
<input type = "file" name = "image" />
<input type = "submit"/>
<ul>
<li>Sent file: <?php echo $_FILES['image']['name']; ?>
<li>File size: <?php echo $_FILES['image']['size']; ?>
<li>File type: <?php echo $_FILES['image']['type'] ?>
</ul>
</form>
</body>
</html>
這一切都在手冊http://php.net/manual/en/features.file-upload.php --- http://php.net/manual/en/features.file-upload.post- method.php --- http://php.net/manual/en/function.chmod.php並使用錯誤報告http://php.net/manual/en/function.error-reporting.php –