Connect to shared folder with php - php

It's possible to connect to a shared folder and list, read or write files in the folder as if it were a local folder with php? I was searching but I haven't found anything that woks for me.

If you intend to access Windows-based Share with SMB protocol, use can use Icewind\SMD library.

It can't possible with only PHP, We can't access the local directory/file using PHP.
But, If you write some Thread or File Watcher task using Java(Watch service) or Python or any other supported technology and send file related events to your PHP web-service or API.
Not sure but if will think in that way...it can be possible.

Related

What is the best and easiest way to access files within a linux vps using its external ip?

I have a game server running in a vps with centos 6 .
The game server stores its status data on a text file and i want to access this file from my website server with php.
The problem is that it is better to do it without installing something link ftp server on the vps. Also i do not know how to set the ftp account directory to my game server directory.
Anyone knows any other simpler way to do so ?
Thanks.
Use a client which supports SFTP if you are able to connect to your server via SSH.
phpseclib handles the SFTP connection without the need to install an extension. For an example on how to download a file with SFTP go here.
If you don't have a webserver installed on your vps, you can use an sftp connection with php, check this question to help you implement it.
sFTP being available by default on most linux OSs you shouldn't have much trouble doing this;

Creating a file in client machine

Is there any possbile solutions in PHP to create a file or directory on the client machine.
Note:
Downloading the file is not a solution to me. only once the user access the website and execute some function and it allows to create a files or directory on the client machine.
Simply, you can't do that in php or any other server side language.
Reason is simple server side application and scripts have access only to local resources where they are launched. So when you run your application on local computer, everything works as you wish for. But because of how HTTP works and because of safety reasons you cannot access user local files.
No it's not possible , except- Flash, Applet ( Not sure ), Microsoft Silverlight ! and for those you will also have to give permission. But i don't think it is a good idea to store file on client machine, try another :)

Is it possible write a PHP script that transfers through FTP a file from a user's computer to an FTP server without using HTML file upload?

I'm not sure how common my request is but here goes:
I have a client who wants to be able to receive files of up to 2GB in size from their customers. The reason why the files are kind of big is because they are graphic design files. Ideally, they would have their customers transfer their files via FTP using an FTP client like Filezilla. However my client has stated that they spend way too much time trying to school people on how to enter FTP credentials into an FTP program and the concept of FTP in general.
So ultimately my client has stated that they would like the customer to be able to use a web interface, which they're already familiar with, to be able to accomplish the same task. For example, they'd like the customer to be able to use a form and hit an upload file button. Simple as that.
At this point I should state that I'm working on a WordPress site on top of a Rackspace Cloud Sites server (shared hosting).
I'm using a WordPress plugin that allows me to do this and it works for small files but not for files approaching 500MB. After speaking to a RS Cloud tech support person I've narrowed it down to the temporary directory /tmp/ in the Apache server. That is the server is not able to write large files into that temporary directory because of their server wide restrictions. That is, they cannot change this to accomodate my needs. They said I would need a dedicated server for that, which, is not an option for me.
After doing some thinking though, I've come to the conclusion that it's silly for me to have to upload a file to the server's temporary directory, only to move the file to the ftp server. So this brings me to my question: is it possible for a web based PHP script to send the file directly from the user's machine, bypass the web server, and send it directly to the FTP server?
If not, do you have any other suggestions? Any help would be appreciated. Thanks.
No, it's not possible at all.
My suggestion? Search and learn how to use HTML5 upload for large files.
Its seams like someone find solution for your problem. Please refer to this question:
Stream FTP download to output
The question was how to stream/pipe file from FTP thru HTTP to the user's browser.
It seams like the answer from #strager is what you need.

How to share or copy files beetween shared folders in linux via PHP

I have a very hard mission to accomplish.
We have a dedicated server outside our company and we also have two servers inside our company.
We need to copy files from server 1 to server 2 programatically via PHP, but the files are inside the /home/server1/files and should go to /home/server2/files.
When the users select 10 files to group accordingly to some criteria, these files must be sent to another server.
We were using copy when we had only one server, and everything was okay...
but now, the system is down, because we have two servers....
When using one server I could use this:
copy('/home/server/files/file.txt', '/home/server/files/group-1/file.txt');
now it has to be:
copy('/home/server1/files/file.txt', '/home/server2/files/group-1/file.txt');
But I don't know how to sent files via servers.
There are quite a few different ways to copy files between servers. I can think of the following:
Send over SSH. You could use php's SCP library
Send via SFTP. Requires a FTP server be setup on server2 and code to be changed to use ftp.
Copy via NFS. Requires NFS to be setup. Once it is you could mount your server2 to /home/server2 and hopefully not need to make any programming changes.
Send via a webservice call (REST or SOAP). Requires code to be setup on server2 to listen for file sending.

How to list a directory in a remote host?

There is a way to list a directory in a remote host without ftp ?
A way using php will be better.
thanks.
No, you can't do that, unless you get some sort of shell access to the remote host, or the remote host provides you with an API to list it (remote API can be an API, or a FILE SERVER FILE SYSTEM access such as NFS or SAMBA).

Categories