upload form:
Code:
<form id="Upload" action="upload.php" enctype="multipart/form-data" method="post">
<p>
<label for="file">File to upload:</label>
<input id="file" type="file" name="file">
</p>
<p>
<label for="submit">Press to...</label>
<input id="submit" type="submit" name="submit" value="Upload me!">
</p>
</form>
Upload page:
Code:
<?
$errors = array(1 => 'php.ini max file size exceeded',
2 => 'html form max file size exceeded',
3 => 'file upload was only partial',
4 => 'no file was attached');
isset($_POST['submit'])
or error('the upload form is neaded');
($_FILES[$fieldname]['error'] == 0)
or error($errors[$_FILES['file']['error']]);
@is_uploaded_file($_FILES['file']['tmp_name'])
or error('not an HTTP upload');
/**************************************************
* now we have the file without errors we can *
* moveit to a new directory using the *
* move_uploaded_file *
* function, orif you want you could add it *
* to a DB if the configs already done..... *
*************************************************/
$my_file = fopen($_FILES['file']['tmp_name'], 'r');
$contents = fread($my_file, filesize($_FILES['file']['tmp_name']));
fclose($my_file);
mysql_query("INSERT INTO DBfiles(id, name, contents)
VALUES('','"
,basename($_FILES['file']['tmp_name'])
."', '".str_replace("'", "\\"."'", $contents)."');");
?>
if you want more info let me know.