user162941
user162941

Reputation: 101

php - multi-step form with file upload

I can't seem to find clarification. I have 7 steps and the second one is to upload a file. The problem I am having is that on the final step when I finalize the form and try and access the temp file it says "Could not access file: ..." (saved in the default tmp folder).

Other multi-step tutorials say to keep it in a temp folder and then move to the appropriate folder when complete. So do they mean I move it from the default temp folder into a temp folder I manage and then when they complete the form move it again to a final folder?

Upvotes: 3

Views: 2593

Answers (2)

hakre
hakre

Reputation: 197795

So do they mean I move it from the default temp folder into a temp folder I manage and then when they complete the form move it again to a final folder?

Yes, exactly. You do the first move on the request that receives the files, because when that request is finished PHP would delete them if they still exist.

See move_uploaded_fileDocs and Handling File Uploads.

Upvotes: 2

cbrandolino
cbrandolino

Reputation: 5883

With "temp folder" they don't mean /temp.

After the upload, you should actually save the file in some folder, maybe with the user's session id as name. Then, with the last step, you should move that file to its definitive location.

Temp files (like, actual temporary file) are destroyed once the program who created them exits (that means usually, in php, after the next output page is sent to the client).

Upvotes: 0

Related Questions