上传远程文件的文件按钮

时间:2023-01-18 00:26:05

Here's the scenario. I have a simple browse button. Right now, it opens up the folder hierarchy on my local computer. (PC).

这是场景。我有一个简单的浏览按钮。现在,它打开了我本地计算机上的文件夹层次结构。 (PC)。

However, I want to pick a file from a remote unix server which I have access to. Is there a way to display the file hierarchy of the remote unix server WITHOUT having to mount the drive?

但是,我想从我有权访问的远程unix服务器中选择一个文件。有没有办法显示远程unix服务器的文件层次结构而不必安装驱动器?

Are there other options other than using a java applet?

除了使用java applet之外还有其他选择吗?

Thanks,
Michael

5 个解决方案

#1


If you don't really want an applet you can do it server-side in PHP by using this something like this to let the user select a folder:

如果你真的不想要一个applet,你可以在PHP中使用这样的东西在服务器端进行,让用户选择一个文件夹:

<?php
$connection = ssh2_connect('host', 22);
ssh2_auth_password($connection, 'username', 'password');

$stream = ssh2_exec($connection, 'ls -a --file-type');
?>

Just parse the $stream variable to identify the folders (the ones ending with /) and present them in a table.

只需解析$ stream变量来识别文件夹(以/结尾的文件夹)并将它们显示在表格中。

I guess this solves your problem. If you want the user to upload a file just put a simple file upload field, Once the user have selected a folder and uploaded a file in a temporal location in the server just move it with SSH too:

我想这可以解决你的问题。如果您希望用户上传文件只是放一个简单的文件上传字段,一旦用户选择了一个文件夹并在服务器的临时位置上传了一个文件,只需用SSH移动它:

<?php
$connection = ssh2_connect('host', 22);
ssh2_auth_password($connection, 'username', 'password');

ssh2_scp_send($connection, '/temporal/filename', '/remote/filename');
?>

For getting this working you need to have enabled SSH2 libraries for PHP in your server.

要使其正常工作,您需要在服务器中为PHP启用SSH2库。

#2


Don't know how it is in Unix, but in Windows, you can either map a drive letter to remote path, or simply type the remote path in the browse dialog (\\server\share\filename)

不知道它在Unix中是怎么回事,但在Windows中,您可以将驱动器号映射到远程路径,或者只需在浏览对话框中键入远程路径(\\ server \ share \ filename)

#3


Instead of using the regular input type file, invoke a Java applet. You can use VFS from apache to access your UNIX machines. VFS API supports many file access protocols.
http://commons.apache.org/vfs/filesystems.html

而不是使用常规输入类型文件,调用Java小程序。您可以使用apache中的VFS来访问UNIX计算机。 VFS API支持许多文件访问协议。 http://commons.apache.org/vfs/filesystems.html

#4


A friend of mine recommended Samba: http://us3.samba.org/samba/

我的一个朋友推荐Samba:http://us3.samba.org/samba/

It apparently lets you link a unix server as a windows file/print server, which should show up in a file browser. :)

它显然允许您将unix服务器链接为Windows文件/打印服务器,它应该显示在文件浏览器中。 :)

#5


I don't know why; I've had much difficulty with installing anything on the solaris machine. So i've decided to go a slightly different route -- I found out that the machine is already mounted properly, so I can simply switch user accounts to access what I need -- without SSH.

我不知道为什么;我在solaris机器上安装任何东西都有很多困难。所以我决定采用稍微不同的路线 - 我发现机器已经正确安装,因此我只需切换用户帐户即可访问我需要的内容 - 无需SSH。

#1


If you don't really want an applet you can do it server-side in PHP by using this something like this to let the user select a folder:

如果你真的不想要一个applet,你可以在PHP中使用这样的东西在服务器端进行,让用户选择一个文件夹:

<?php
$connection = ssh2_connect('host', 22);
ssh2_auth_password($connection, 'username', 'password');

$stream = ssh2_exec($connection, 'ls -a --file-type');
?>

Just parse the $stream variable to identify the folders (the ones ending with /) and present them in a table.

只需解析$ stream变量来识别文件夹(以/结尾的文件夹)并将它们显示在表格中。

I guess this solves your problem. If you want the user to upload a file just put a simple file upload field, Once the user have selected a folder and uploaded a file in a temporal location in the server just move it with SSH too:

我想这可以解决你的问题。如果您希望用户上传文件只是放一个简单的文件上传字段,一旦用户选择了一个文件夹并在服务器的临时位置上传了一个文件,只需用SSH移动它:

<?php
$connection = ssh2_connect('host', 22);
ssh2_auth_password($connection, 'username', 'password');

ssh2_scp_send($connection, '/temporal/filename', '/remote/filename');
?>

For getting this working you need to have enabled SSH2 libraries for PHP in your server.

要使其正常工作,您需要在服务器中为PHP启用SSH2库。

#2


Don't know how it is in Unix, but in Windows, you can either map a drive letter to remote path, or simply type the remote path in the browse dialog (\\server\share\filename)

不知道它在Unix中是怎么回事,但在Windows中,您可以将驱动器号映射到远程路径,或者只需在浏览对话框中键入远程路径(\\ server \ share \ filename)

#3


Instead of using the regular input type file, invoke a Java applet. You can use VFS from apache to access your UNIX machines. VFS API supports many file access protocols.
http://commons.apache.org/vfs/filesystems.html

而不是使用常规输入类型文件,调用Java小程序。您可以使用apache中的VFS来访问UNIX计算机。 VFS API支持许多文件访问协议。 http://commons.apache.org/vfs/filesystems.html

#4


A friend of mine recommended Samba: http://us3.samba.org/samba/

我的一个朋友推荐Samba:http://us3.samba.org/samba/

It apparently lets you link a unix server as a windows file/print server, which should show up in a file browser. :)

它显然允许您将unix服务器链接为Windows文件/打印服务器,它应该显示在文件浏览器中。 :)

#5


I don't know why; I've had much difficulty with installing anything on the solaris machine. So i've decided to go a slightly different route -- I found out that the machine is already mounted properly, so I can simply switch user accounts to access what I need -- without SSH.

我不知道为什么;我在solaris机器上安装任何东西都有很多困难。所以我决定采用稍微不同的路线 - 我发现机器已经正确安装,因此我只需切换用户帐户即可访问我需要的内容 - 无需SSH。