Alter upload script

Hi guys

I’m a little stuck with this script:

[php]

please select a file
<?php if (isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fileType = (get_magic_quotes_gpc() == 0 ? mysql_real_escape_string( $_FILES['userfile']['type']) : mysql_real_escape_string( stripslashes($_FILES['userfile']))); $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if (!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $con = mysql_connect('localhost', 'root', 'root') or die(mysql_error()); $db = mysql_select_db('test', $con); if ($db) { $query = "INSERT INTO upload (name, size, type, content ) " . "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); mysql_close(); echo "
File $fileName uploaded
"; } else { echo "file upload failed"; } } ?>

I want to add a username and id field to submit with the file?

[/php]

Does that “upload” table already have those fields? Then you could add the field names.

Otherwise you would need to figure out where to store the names, and how to tie them back to the upload, and make a separate query.

Sponsor our Newsletter | Privacy Policy | Terms of Service