Page 1 of 1

Uploading files via php

Posted: Fri Nov 10, 2006 8:40 am
by amir
Hi,

I am working on uploading files (word, excel files etc.) via php. As I understand it, files can either be stored within (1) a database table (by using php's file_get_contents function), or (2) on a directory in the server. I assume, however, that the file_get_contents function can only be utilized for text files, as opposed to excel and word files, but please correct me if I am wrong.

Also, lets assume that the user attaches files as part of an input form whereby the user presses a file upload button after they have selected the files with the browse button(s). At that point, am I correct in assuming that I should store the files in a temporary upload directory and then only transfer them to their final resting place if the user actually submits the entire form. This makes sense to me; does it make sense to you?

I look forward to your thoughts.

Thanks!

Posted: Fri Nov 10, 2006 12:15 pm
by John Cartwright
function), or (2) on a directory in the server. I assume, however, that the file_get_contents function can only be utilized for text files, as opposed to excel and word files, but please correct me if I am wrong.
file_get_contents() wrote:Note: This function is binary-safe.
At that point, am I correct in assuming that I should store the files in a temporary upload directory and then only transfer them to their final resting place if the user actually submits the entire form. This makes sense to me; does it make sense to you?
If you are using a form to upload file, a temporary file will have already been created for you, accessible by the $_FILES superglobal. If that's not what you meant, such using a multi-step form whereby the uploaded files may become unwanted, then sure create another temporary directory that may easily be flushed of all it's contents (garbage cleanup)