php script that uploads BLOB data to mySQL

Hey Guys,

Here’s a script, everything seems to be in working order execpt my one $strDesc variable. Comments are included to help it make it easier on the eyes…ch-check it out:

[php]<?php

// GrabFile.php: Takes the details

// of the new file posted as part

// of the form and adds it to the

// myBlobs table of myFiles DB.

global $strDesc;

global $fileUpload;

global $fileUpload_name;

global $fileUpload_size;

global $fileUpload_type;

// Make sure both a description and

// file have been entered

if(empty($strDesc) || $fileUpload == “none”)

die(“You must enter both a description and file”);

// Database connection variables

$dbServer = “localhost”;

$dbDatabase = “myfiles”;

$dbUser = “root”;

$dbPass = “beagle”;

$fileHandle = fopen($fileUpload, “rb”);

$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 myBlobs VALUES ";

$dbQuery .= “(0, ‘$strDesc’, ‘$fileContent’, ‘$fileUpload_type’)”;

mysql_query($dbQuery) or die(“Couldn’t add file to database”);

echo “

File Uploaded

”;

echo “The details of the uploaded file are shown below:

”;

echo "File name: $fileUpload_name
";

echo "File type: $fileUpload_type
";

echo "File size: $fileUpload_size
";

echo "Uploaded to: $fileUpload

";

echo “Add Another File”;
[/php]

The error returned is ‘You must enter both a description and file’ despite me most obviously doing so in my previous getfiles.php page.

What gives?

Jack

have you echoed out the 2 variables to make sure they are what you think they are? If they aren’t - why not, if they are try adding parens around your condition statements so they are nicely grouped.

Sponsor our Newsletter | Privacy Policy | Terms of Service