[英]PHP file Uploads not Working
I'm working on a web application in php that allows users to upload files with a specified structure (file type could be cvs or excel sheets) and the app will extract data from the files and insert them into a database. 我正在使用php中的Web应用程序进行工作,该应用程序允许用户上传具有指定结构(文件类型可以是cvs或excel表)的文件,并且该应用程序将从文件中提取数据并将其插入数据库中。
I can't get my app to upload files and I've been trying for 2 days, I checked the php.ini for max upload size ,max post size , file uploads on, temp directory set to /tmp which is accessible by all users. 我无法让我的应用上传文件,并且已经尝试了2天,我检查了php.ini以获取最大上传大小,最大发布大小,文件上传位置,设置为/ tmp的temp目录,所有人均可访问用户。
I also checked the syntax of php and html and made sure I was using the right encoding type, I also checked the permissions of the upload directory but the _FILES variable is always empty, note : my web server is hosted on amazon ec2 running Ubuntu 14.04 LTS. 我还检查了php和html的语法,并确保使用正确的编码类型,还检查了上传目录的权限,但_FILES变量始终为空,请注意:我的Web服务器托管在运行Ubuntu 14.04的Amazon ec2上LTS。
here's one of the codes I tried and it's output: 这是我尝试过的代码之一,它的输出是:
<?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>
and the outputted echo is only Array ( ) whether I upload a file or not. 无论我是否上传文件,输出的回声只是Array()。
anyone faced something like this before ? 有人遇到过这样的事情吗?
<?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.