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.
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.
mixed <strong>uploadFile</strong> (string $target, string $reference [, string $fileName])
Returns the full path of the uploaded file on success
Returns FALSE on failure
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');
?>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
