[英]PHP csv upload file not on the server
I wrote a simple script to upload a csv file and then update a database table. 我编写了一个简单的脚本来上载csv文件,然后更新数据库表。 However, even though I am getting a temp $_FILES['update']['tmp_name'] path, the file is not at this location on the server.
但是,即使我得到了临时$ _FILES ['update'] ['tmp_name']路径,该文件也不在服务器上的该位置。 Does anyone know what this means?
有人知道这意味着什么吗? could it be a permissions issue?
可能是权限问题? This is a Godaddy shared hosting account.
这是一个Godaddy共享托管帐户。
Here's my form and the handler (the database piece is not in place yet. I'm just trying to get file contents at this point): 这是我的表单和处理程序(数据库块尚未安装。我现在只是想获取文件内容):
<div class="admin-section" style="margin-left:10%;">
<?php
if ( !empty($_POST['uploadFile']) ) {
$name = $_FILES['update']['name'];
echo $_FILES['update']['type'] . '<br />';
echo $_FILES['update']['size'] . '<br />';
$path = $_FILES['update']['tmp_name'];
echo $_FILES['update']['error'] . '<br />';
$file = $path . '/' . $name;
$file_open = fopen($file, 'r');
$data = fgetcsv( $file_open, 1000, ',');
print_r($data);
}
?>
<form enctype="multipart/form-data" action="#" method=post>
<label>Select a CSV or XLS file to up load from your computer</label><br />
<p>
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="hidden" name="uploadFile" value="yes" />
<input type=file name=update />
</p>
<p>
<input type=submit name=Upload />
</p>
</form>
</div>
The error I get is fopen(/tmp/php05Lebo/certificate-users.csv): failed to open stream: No such file or directory , and sure enough, that folder does not exist in /tmp. 我得到的错误是fopen(/tmp/php05Lebo/certificate-users.csv):无法打开流:没有这样的文件或目录 ,而且可以肯定的是,该文件夹在/ tmp中不存在。 Thanks!
谢谢!
You never moved the temp file to the $file path, so your $file is invalid. 您从未将临时文件移动到$ file路径,因此$ file无效。 Either use
move_uploaded_file()
to rename the temp file and save it on your server or if you don't care about accessing the file after the initial upload, set $file = $_FILES['update']['tmp_name']
使用
move_uploaded_file()
重命名临时文件并将其保存在您的服务器上,或者如果您不关心初始上传后访问该文件,请设置$file = $_FILES['update']['tmp_name']
<?php
if ( !empty($_POST['uploadFile']) ) {
$name = $_FILES['update']['name'];
echo $_FILES['update']['type'] . '<br />';
echo $_FILES['update']['size'] . '<br />';
$path = $_FILES['update']['tmp_name'];
echo $_FILES['update']['error'] . '<br />';
if(move_uploaded_file($_FILES['update']['tmp_name']),$name){
$file_open = fopen($name, 'r');
$data = fgetcsv( $file_open, 1000, ',');
print_r($data);
}else
echo 'Unable to upload file';
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.