1

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?

2
  • for Q1 maybe show file with base64 ? for Q2 don't know Commented Dec 23, 2014 at 6:48
  • 1
    If you want to do something with the uploaded file later, you will have to move/save it somewhere via move_uploaded_file(), because the temporary file will become inaccessible to you once your invoked script ends. You could save it to your own temp folder and display it or whatever and later on move it again to its final destination. If you know the file is small, you could also save it in your session as a string and write it back to disk when saving your data. Commented Dec 23, 2014 at 7:02

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.