[英]PHP file Uploads not Working
我正在使用php中的Web應用程序進行工作,該應用程序允許用戶上傳具有指定結構(文件類型可以是cvs或excel表)的文件,並且該應用程序將從文件中提取數據並將其插入數據庫中。
我無法讓我的應用上傳文件,並且已經嘗試了2天,我檢查了php.ini以獲取最大上傳大小,最大發布大小,文件上傳位置,設置為/ tmp的temp目錄,所有人均可訪問用戶。
我還檢查了php和html的語法,並確保使用正確的編碼類型,還檢查了上傳目錄的權限,但_FILES變量始終為空,請注意:我的Web服務器托管在運行Ubuntu 14.04的Amazon ec2上LTS。
這是我嘗試過的代碼之一,它的輸出是:
<?php
echo $_FILES['file']['error'];
print_r($_FILES);
echo $name = $_FILES['file']['name'];
?>
<html>
<header>
<title> Test Page</title>
</header>
<body>
<form action="Test.php" method="POST" enctype="multipart/formdata">
<input type="file" name="file" id="file" /><br><br>
<input type="submit" value="submit" />
</form>
</body>
<html>
無論我是否上傳文件,輸出的回聲只是Array()。
有人遇到過這樣的事情嗎?
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
session_start();
$file_tmp= $_FILES['image']['tmp_name'];
header("Test.php");
}
?>
<html>
<header>
<title> helllllllo </title>
</header>
<body>
<form action="form-validation" method="POST" enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" >
<div class="form-row form-input-name-row">
<label>
<span>Profile Image</span>
<input type="file" name="image" id="file" onchange="readURL(this);" data-val="true" style="margin-bottom:10px;" />
<div class="form-row form-input-name-row">
<img id="blah" src="#" alt="your image" style="width: 100px; display: none; margin-bottom:10px;" />
</div>
</div>
<input type="submit" value="submit" />
</form>
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').show().attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.