Simple PHP File Upload
This is a very simple, yet fully functional PHP script/function to upload files to your website. Usage and integration is simple, file uploads can be as simple as adding one line to your PHP form processing scripts. All you do is call a function. UPDATED: Now supports uploading multiple files.
After uploading a file to the web server, this function will move the file referenced by "$reference" From the PHP temporary file name & path to the "$target" path With the file name of basename($_FILES[reference][name]) or $fileName is it is provided. Note: With multiple files upload, the $fileName parameter is ignored, the files names will be the same as the original.
mixed <strong>uploadFile</strong> (string $target, string $reference [, string $fileName])
Returns the full path of the uploaded file on success
Returns FALSE on failure
With multiple file uploads, it returns: array of "array('file', 'result')"
WARNING: This function will always replace files.
ADDITIONAL: This function will attempt to create subdirectores if they do not exists
Copy "fileFunctions.php" to your web server and include the "fileFunctions.php" script at the top of your form processor script:
<?php
include('fileFunctions.php');
?>Assuming you have the following form:
<form name="form1" enctype="multipart/form-data" method="post">
Upload File: <input type="file" name="upload" id="upload" />
<input type="submit" name="submit" value="Submit" />
</form>
Just add the following line to your form processing script:
<?php
$result = uploadFile('files', 'upload');
?>If you'd like to enable upload of multiple files, just add "[]" to the end of the file field form element name. So, above, you would simply create multiple file input fields and name them all name="upload[]". For a complete example, see the file named "uploadSampleCode.php" that is included in the archive.
Download it at: http://www.unibia.com/unibia/dev/downloads/simplePHPUpload.tar