Click to See Complete Forum and Search --> : Blobbing Data With PHP and MySQL help...


supir
12-23-2005, 02:24 AM
hi guys...this the code i copy from ttp://www.devarticles.com/c/a/MySQL/Blobbing-Data-With-PHP-and-MySQL/2/..exactly..copy the code and paste it on dreamweaver..
its run smoothly BUT.............everytime i clicked "upload", it show "You must enter both a description and file"....can u help me..here..i posted a code :
grabfile.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 our 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 = "mobster";
$dbUser = "ajad";
$dbPass = "ajad2";

$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");

echo "<h1>File Uploaded</h1>";

echo "The details of the uploaded file are shown below:<br><br>";

echo "<b>File name:</b> $fileUpload_name <br>";

echo "<b>File type:</b> $fileUpload_type <br>";

echo "<b>File size:</b> $fileUpload_size <br>";

echo "<b>Uploaded to:</b> $fileUpload <br><br>";

echo "<a href='uploadfile.php'>Add Another File</a>";

?>

thanks...

LiLcRaZyFuZzY
12-23-2005, 05:04 AM
Hi,
It is not working because register globals (http://php.net/register_globals) are set to off by default since PHP version 4.2.0.
I suppose that your version of PHP is newer and (the article is from 2002) their is most probably older ;)

in order to make it work, you'll have to explicitly take your variables from the POST array:

instead of:

global $strDesc;
global $fileUpload;
global $fileUpload_name;
global $fileUpload_size;
global $fileUpload_type;


write(if your HTML is the same as in the article and your method is set to post):

$strDesc = $_POST['strDesc'];
$fileUpload = $_FILE['fileUpload'];
$fileUpload_name = $_FILE['fileUpload']['name'];
$fileUpload_type = $_FILE['fileUpload']['type'];
$fileUpload_size = $_FILE['fileUpload']['size'];


not sure if it will work, i did not test it
good luck

supir
12-23-2005, 06:33 PM
hi bro..thank for helping me...but still got a porblem here...
"Notice: Undefined index: strDesc in l:\mobster\blob\grabfile.php on line 13

Notice: Undefined variable: _FILE in l:\mobster\blob\grabfile.php on line 14

Notice: Undefined variable: _FILE in l:\mobster\blob\grabfile.php on line 15

Notice: Undefined variable: _FILE in l:\mobster\blob\grabfile.php on line 16

Notice: Undefined variable: _FILE in l:\mobster\blob\grabfile.php on line 17"

its gonna like that...and no file were upload into database.....sorry again..
can help me again..??

LiLcRaZyFuZzY
12-24-2005, 12:44 AM
yes, your PHP version might be lower than 4.1.0.
read this:
http://us3.php.net/manual/en/reserved.variables.php#reserved.variables.files

supir
12-27-2005, 08:09 PM
its done bro..but i got another problem ....."Warning: fread(): supplied argument is not a valid stream resource in.....is it cause of the version of PHP or apache itself?

LiLcRaZyFuZzY
12-29-2005, 07:25 AM
could you post the code?

supir
12-29-2005, 06:16 PM
bro..the code already post..in my first post above..thanks bro..

supir
01-02-2006, 06:59 PM
somebody..help me

acorbelli
01-02-2006, 07:18 PM
You need to check to make sure the file was actually opened. I can nearly guarantee you that you're passing an invalid filename, or trying to access a file without the correct permissions, which is causing fopen() to fail. Put everything after the line with fopen() in an if statement that looks like this:

//Other code up here
$fileHandle = fopen($fileUpload, "r");
if ($fileHandle)
{
//REST OF YOUR CODE HERE
}
else
{
echo "Was not able to open file";
}


If "Was not able to open file" prints out, then you know that either you've got a filename wrong, you're handling a file upload wrong, or you do not have the correct permissions set. I would need to see the upload script as well as the rest of the scripts to know which though. But in the interim, you can start looking there. (I bet you didn't correctly set the permissions of the file, or forgot to move it to a non-temporary directory).

PS:
I think she's too polite to mention it, but lilcrazyfuzzy is not a "bro" as it were...