Pergunta

I develop some python applications so I know how to do this in python locally, but am working with some PHP developers (I know nothing of PHP) who say this can't be done in PHP. This is the idea: A php driven remote website which creates / hosts files. Using a web browser I want to download from this website a series of folders and files onto the local machine overwriting already existing files/folders with the same name. So in my browser I click on a download button which asks me to browse to a local or network folder to download the folders and files to. Currently we are just downloading a single .zip file containing all these files and folders which we have to unzip and manually move, copy paste, etc, very messy and cumbersome. There must be a better way with PHP and some other language?

Foi útil?

Solução

No, it's not possible to access from a PHP (server-side language) to the Client Machine (from a Browser) and manipulate directly his file system, hard drive, or something like that. This is not the way it works.

Just think about it for a moment, if it could be accomplish, we have serious security threat, for example we visit a page like somebadassdude.com and they have a PHP script that create unlimited folders and files to fill up all our HD... and that is soft.

But hopefully the browsers dont allow this by security design.

Look at this: Web Diagram

As you can see at the Diagram, the Browser and the Server response each other through HTTP Requests & Responses. There's no a communication between them like a local program running at the Client OS. You treat with his Browser, and there's no way to command the Browser to manipulate the client hard-disk, and if that can happend, look at the security consern that I mentioned before.

To be more clearer, your PHP script is running at your server, not at the client machine. It only response when a user/browser request a specific resource at your server, and response with a HTTP Response, and it can contain HTML, or Json, or a File (to be downloaded or visualized by external program), or whatever.

You have limited options:

  • If it is something for a Intranet, or local network, and you have access to that network, locally or remotely like with a VPN access. You could share a folder over network, in that way you can use a Php Script or Python script in order to create the folders and copy the files to it, without have to download a zip, and unzip manually from the Browser.
  • Using a Java Applet. Why? Because a Java Applet runs on the Client Side, so you have access to his computer (if the user allow it), and you certeinly can manipulate (create, delete, read, etc. folders and files) his hard-drive. So when the user choose the files to download, you fire the Java Applet, and let em request to the server the files that the user has marked. When you have the files downloaded, create or overwrite the files on the client machine.
  • Create and run a program in the Client Machine, in detriment of a Web Page, by this way you gain the needed flexibility. But of course, it have his own complexities.

So IHMO i think the Java Applet maybe is the best suited solution for you:

  • Do not have to change much your actual business model
  • It doesn't require a large time investment.
  • It is cross-platform, Java can work on a plenty of operating systems, and Java Applets in the most popular browsers.

By the way, I personally dislike Java, but it's a tool, and you have to use the right tool for a job.

Cheers.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top