使用输入类型文件选择文件夹路径 [英] Selecting folder path using input type file

查看:64
本文介绍了使用输入类型文件选择文件夹路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PHP中遇到问题。我正在使用< input type = file> 来获取用户的文件名。
基本上我想存储正好的文件夹路径而不是文件,所以当我使用超链接显示路径时,用户可以打开目录。

I have a problem in PHP. I am using <input type=file> to get the file name from the user. Basically I want to store the just folder path and not the file, so that when I display the path using hyperlink, the user can open the directory.

但是使用< input type = file> ,用户必须选择一个文件,然后只有文件文本框得到充实。现在我想剥离文件名的最后部分。

But using <input type=file> the user has to select a file then only the file textbox will get filled. Now I want to strip off the last part of the filename.

我该怎么做?或者有没有更好的方法来解决这个问题?

How do I do this ? Or is there a better way to solve this problem?

编辑:

说一个名为1.html的文件:

I am using something like this in say a file named 1.html:

<form method="post" action="update.php">
    <input type="file" name="attachment" id="attachment"></td> </tr>
 </form>

现在,在update.php中,我使用类似这样的内容:

Now, in update.php I am using something like this:

$logpath1=$_POST['attachment'];

基本上,我正在获取用户选择的$ logpath1中的文件名。
但是,输入类型=文件只适用于文件而不适用于文件夹。

Basically I am getting the file name in $logpath1 that user selects. But the thing is input type = file will only work for files and not folders.

那么,如何从路径中剥离文件名?

So, how do I strip the filename from the path?



Example: if user selects,

C:\Documents and Settings\myusee\Desktop\new 2.cpp

我想剥离新的2.cpp

我不知道如何使用爆炸。此外,我正在 XAMPP Lite 上运行。

I am not sure how can I use explode. Moreover I am running on XAMPP Lite.

推荐答案

你可以用另一种方法做到这一点,把一个隐藏的字段放在< input type =hiddenid =somethingname =something/> 并使用jQuery(JavaScript)选择文件输入框的值,并在提交之前将其放入隐藏字段中,提交后您将拥有完整的路径,不知道它是否有效,但值得一试。

You can do this another way, put a hidden field <input type="hidden" id="something" name="something" /> and use jQuery (JavaScript) to select the value of the file input box and put it into hidden field before submission and after submission you will have a whole path, I don't know if it works but it's worth a try.

这篇关于使用输入类型文件选择文件夹路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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