获取上载文件的完整PATH-PHP [英] Getting complete PATH of uploaded file - PHP

查看:68
本文介绍了获取上载文件的完整PATH-PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单(HTML,PHP),允许最终用户上传文件,以使用上传文件(特别是.csv)中的记录来更新数据库(MySQL).但是,在phpscript中,我只能获取文件名,而不能获取特定文件的完整路径.由于这个原因,fopen()失败.谁能让我知道如何找到完整的路径?

I have a form(HTML, PHP) that lets the end user upload a file to update the database(MySQL) with the records in the uploaded file(specifically .csv). However, in the phpscript, I can only get the filename and not the complete path of the file specificed. fopen() fails due to this reason. Can anyone please let me know how I can work on finding the complete path?

HTML代码:

<html>
<head>
</head>
<body>
<form method="POST" action="upload.php" enctype="multipart/form-data">
    <p>File to upload : <input type ="file" name = "UploadFileName"></p><br />
    <input type = "submit" name = "Submit" value = "Press THIS to upload">
</form>
</body>
</html>

PHP脚本:

<?php
   .....
......
   $handle = fopen($_FILES["UploadFileName"]["name"], "r"); # fopen(test.csv) [function.fopen]: failed to open stream: No such file or directory
?>

推荐答案

name是指客户端上的文件名.要在服务器端上获取文件名(包括完整路径),您需要使用tmp_name:

name refers to the filename on the client-side. To get the filename (including the full path) on the server-side, you need to use tmp_name:

$handle = fopen($_FILES["UploadFileName"]["tmp_name"], 'r');

这篇关于获取上载文件的完整PATH-PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆