Question

I've been searching for a good 3 hours, and I'm stumped on how to do something I think is pretty simple (famous last words...)

Basically, I'm building a site that allows the user to upload a pdf file. The URL of this file is stored in a database, along with the name and a few other details. I am trying to work out how to either:

-Provide an "upload" box/button/area that a user can select a file, upload it, and then have the URL of where the file was uploaded stored in a database.

OR

-Use a separate upload script, and have the user upload the file. Then, (on a possibly separate page, I don't mind) provide a file browser, which would allow the user to browse a directory, and select a file, with the url of that file passed through to the PHP form.

I don't mind which way it is done, as long as the desired outcome of having a file uploaded and the url added to a database.

Or am I out of the reach of PHP? Is my best bet uploading files via a bare php uploader, then manually entering the url of the file uploaded into a textbox on a php form?

Any help is much appreciated!

Was it helpful?

Solution

  1. create a htmlform, make sure to set enctype to a value of "multipart/form-data"
  2. in PHP you should be able to get the file namefrom the $_FILE global variable
  3. save it to a directory on the server.
  4. the url of your document will we http://serverroot/{directory name}/filename.pdf -> directory name is the name of the directory on the serve you saved the file in
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top