Get directory listing from any URL - php

As far as I have read, PHP can only get the file listing from local server on which script is running.
What I need is the list of files in a directory on an external URL, which is not FTP but an HTTP URL, such as www.google.com. Is this possible in PHP?
Here is example of what I want (but FDM is C++ app)!

You can only see this if the webserver allows it

This is not possible in any language.
If a remote server does not want to list directory contents (i.e. if it's configured not to), no external script can generate one; that would be insecure.

Free download manager does not show the files in the folder, but all the links found on the web page. You can get a web page with curl, and grab all links from it (using regular expressions), then download the linked pages - that's how web-spiders are build. But you cannot get list of the files that are on the server, only the one that are linked in a publicly available web-page.

You can see server files only if the server allows that option, alternative you have to install your own script that will do that work for you indepent of the server settings. That also means that you have to have access on the server that you like to list the files.

Related

Prevent download of PDF file from site

I have files stored in the server with the Plesk panel, currently, any person with the link of my site can access the file and download it.
Is there any way to prevent the download for all the users?
The general approach is to create a folder that is not in the root folder of the web site. In other words, you don't allow nor have valid URL's to a folder as a result. This does mean then you have to build some type of web page that can say list out some files and a button to click to download such files.
In other words, no valid url's exist. This tends to suggest that you have some type of grid or display of files. often even a database table to drive such a display is used.
When the user clicks on say a button on that grid row, then code behind can fetch the file, and "stream" it down to the user. The end result is thus no valid url's or resolvable path to the files exists.
Also, from IIS, turn off directory browsing. and thus again no valid URL's to the files exists.
The other approach? You can build a custom http handler. This approach is quite common. That way, any url that ends in .pdf will be trapped, and thus not allowed. As noted, this again means you have to provide a "list" of files, and a button to download - and again you can then stream the file from the server.
So there is quite a few ways, but ultimate, I as a general rule don't allow files to be downloaded or even accessed by URL's. I always provide some kind of web page, and a list of choices for the user. The code behind is what actually fetches the file, and then streams it down to the browser.
So, you can
Search for how to build a custom http handler for pdf files in asp.net
Search for how to stream a file to users in asp.net
how to turn off directory browsing in IIS.
There are a truckload of options here - in fact too many to really post and explain in Stack Overflow answer.

Chrome developer tools - is there a way to check current's file name?

I have a code of online shop on Prestashop, and I have for example content="Shop on PrestaShop" in meta-data of current page, but when I'm trying to find that String in project in Webstorm to localize which page file it is, I get nothing.
So I guess it's some PHP magic working there. So now I have huge problem with finding proper file in order to change that String. Is it possible to check a filename and it's extension via Google developer tools? I'm starting site from server, not localhost.
You can only find the files that are delivered to client's machine in chrome developers tools by visiting:
Inspect > Sources
The server side files can be visible only if you can see them in URL. If the path is re-written using something like .htaccess in apache, then there's really nothing that you can do to find out the file.
These type of files are meant to be present only to hide the actual file path.

Can you force file download with the Dropbox API?

I'm trying to build a basic web application using the Dropbox API. I have the file upload/folder listing etc. working but cannot find in the documentation how to force the file to download to the user's browser. Is this possible?
If it is can someone point me in the right direction? I'm using the standard PHP SDK.
Dropbox.com: How do I force a file to download from the web
Force a file or folder to download
To cause the browser to download a file or folder rather than display
it, you can use dl=1 as a query parameter in your URL. For example:
https://www.dropbox.com/s/qmocfrco2t0d28o/Fluffbeast.docx?dl=1 Note
that the original share link URL may contain query string parameters
already (e.g. dl=0), so app developers should make sure to properly
parse the URL and add or modify parameters as needed.
And if that doesn't suffice you can check Wikihow: How to Force a File to Download from the Web on Dropbox, with nice screenshots.
If this is not what you had in mind you have clarified that in your question. You still can do that now.

Can a web application open a pdf file that exists on the client side

I have an ASP page, in which the user chooses a value (e.g drawingId) from a list box, and according to this value, ASP builds/calculates a file path, e.g. c:\drawings\file1.pdf, in order to show this pdf file to the user. This path refers to the client's computer, where these pdf files are stored. The server queries the database and knows only the association between the drawingId and the path at the client's computer.
How can I open this pdf file?
I've read similar questions, like How can my web application written in Java open a file on the client side? or Can javascript access a filesystem?, but I haven't understood how to proceed.
I would like this to work with all browsers and also implement this functionality in a PHP site.
Use file:///
e.g. file:///c:/filename.pdf
Well I guess after user selects option from a list box, you could construct the path and redirect user to that path which should open the pdf file
eg.
file:///C:/foldername/filename.pdf
it not possible to open client side file from server side code as it running at server side, also due to some security reason browser does not allow to browse client location
refer link Open local folder from link

Opening a word document on clients PC, through a PHP application

I am developing a web application in PHP as a replacement of Microsoft Access based application for a company.
In old access application in their database they were storing a link to a word document, which further links to other documents. Now in access form they are showing that link, when click on that link they can open the word document from a common folder in a network PC and make any changes the that file (pretty easy for user).
Is there any way to do the same through the web-based application?
What if I just move the common folder in my www directory?
In that case they can open the file easily, but if they have to make any change they have to download the file on their PC, and the changes will be done to their local file not in the file that is on server. So they need to move file to server back or ask network admin for moving the file back to the server
What if I keep common folder in a network PC it self and try to access it form there?
Just by clicking I can’t open a file form client’s or any other network PC. For this when click on the link I have to open & read file through PHP on web server. Using any document to PDF converter, I have to convert the file format and then open it in browser. Here the problem are,
Still I can’t make changes in file and
I have to fix about the format that I might need to convert in PDF.
I am not sure how the other documents that are linked to the main document will work.
There's two ways of doing this: (a) let the user download it from your web application, either statically (stored on the web server) or dynamically (processed in PHP or even built in real-time).
Or, (b) use a file link to a known location on the user's disk, such as file://C:/mydoc.doc.
Addendum - if you want to write to the file in your web app, but also have the user open the same copy, use (b) rather than (a). This presumes that the location of the file is available through a local or network path.

Categories