Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

uploading files to MySQL database using PHP

Status
Not open for further replies.

mrsbean

Technical User
Jul 14, 2004
203
US
I'm fairly new to PHP. I have the following script:

Code:
$fileUpload = "EXACT_PATH_TO_TEMPORARY_FOLDER_WHICH_I_KNOW_EXISTS/".$_REQUEST[fileUpload];
$fileHandle = fopen($fileUpload, "r");
$fileContent = fread($fileHandle, $fileUpload_size);
$fileContent = addslashes($fileContent);
$sConn = mysql_connect($dbServer, $dbUser, $dbPass)

or die("Couldn't connect to database server");

$dConn = mysql_select_db($dbDatabase, $sConn)
or die("Couldn't connect to database $dbDatabase");

$dbQuery = "INSERT INTO phForms VALUES ";
$dbQuery .= "(0, '$fileUpload_name', '$fileContent', '$file
Upload_type', '$fileUpload_size', '$strDesc')";


mysql_query($dbQuery) or die("Couldn't add file to database");

fclose($fileHandle);

The script mostly works ... It does insert a row into the MySQL database. All of the fields in that row appear except for the most important one -- the one with the file in it. Can anybody tell me what I'm doing wrong?

MrsBean
 
the file information is stored in the $_FILES superglobal. the file name that php uses to store the file in the temporary upload directory is found in $_FILES['element name']['tmp_name'] where element name is the name of the html file element that you put in your form.

there are some good upload handling scripts on php.net:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top