kosherjellyfish
kosherjellyfish

Reputation: 373

PHP - Questions on File Upload

I've got a PHP form which takes in both data and file upload. The following graphic shows the different parts of the form:

fileuploadsequence

Part 1 - Allow user to input some form fields, and upload file.

Part 2 - Display the submitted details, and view uploaded file. If edits needed to be done, proceed to Part 2.1.

Part 2.1 - Edit Details

Part 3 - Write into database and shift uploaded file into folder.

Question:

1) In Part 2, I am able to get the file details using $_FILES["fileupload"]["name"]. Is there a way to view the file (click and open the file) when it's residing within the temp-location of the server?

2) Am I able to only do shifting of the file location when I'm in Step 3?

Upvotes: 1

Views: 191

Answers (1)

Hans Dubois
Hans Dubois

Reputation: 269

For question 1: The file will be removed at the end of the request. So if you want to view it you either need to get it's contents (file_get_contents) or move it to a different location (move_uploaded_file)

For question 2: Since the file is removed after it's request the safest way to relocate it on step 2, with move_uploaded_file.

Upvotes: 1

Related Questions