Abdul Jabbar
Abdul Jabbar

Reputation: 2573

File Reading in PHP

I want to access url of file which user select through pop up file directory navigation window. My browse button tag is:

<input  type="file" id="loadFile"/>

On the back end, i can access the file url in javascript, but not sure how to do it in PHP.

Upvotes: 0

Views: 66

Answers (1)

gview
gview

Reputation: 15361

You have to have the correct enctype for the form.

Otherwise, you utilize the $_FILES super global.

This is covered extensively in the PHP Manual regarding uploads.

The original filename is available in $_FILES['load file']['name']

Since it seems that you actually want a way to have the user provide a url to a file, the way to handle that is to simply implement a text input and accept the url there, and process the url on the server, using an HTTP client that fetches and stores the file on the user's behalf.

For years people have been using the curl extension, which is fast and highly functional. There are also a number of client libraries written in php like Guzzle.

Upvotes: 1

Related Questions