Hello everyone,
I would really appreciate if anyone could please help me out here. I am trying to read the user's input in one page and then trying to display it in another page (want to let my users upload a file from their machine and save them in my database).
here's what i have so far....

in File_1.php I am collecting the file's path/location and description and saving then in two different variables:

<!-- letting the browser know that we are sending files from the client's machine to the server -->
<form enctype="multipart/form-data" name="frmUploadFile" action="File_2.php" method="post">

<br>Please select a file and give a description of it.<br>

<!-- insert the file location  -->
<p>File Location: 

<input type="file" name="fileUpload" size="50">

<!-- insert the file description  -->  
<p>File Description: 

<input type="text" name="fileDesc" size="50">

<td width="67%">
<input type="submit" value="Submit" name="submit">

and in File_2.php, I am checking if the user provided both fields:

// declared five global variables
global $fileName;  
global $fileSize;
global $fileDesc;  
global $fileType;  
global $fileUpload;

// Making sure both the file's location and description have been entered
if($fileUpload == "none")
	die("You haven't selected any files."); 
	die("You didn't put the file description.");

Now my problem is even though I am providing both fields in File_1.php, I am ALWAYS getting the message "You didn't put the file description." Can anyone please tell me what I am doing wrong?

Thank you in advance!!!

PS: i omitted few lines here that handled the font style/size etc. guessing that's not related to my question.

try to echo $fileDesc or echo $_POST on File_2.php and see if you get any value.

May be i did some thing wrong, because i did

echo $fileUpload;
echo $fileDesc;

in my File_2.php file, and it's returning nothing :(
any ideas plz?

have you tried..

echo $_POST['fileDesc'];

I think you did not set any value to the global variables.

Thank you for your reply!!!
sorry, that time i didn't try "echo $_POST" and after doing so it's showing me the file description ("The apple") but if i do....

echo $HTTP_GET_VARS['fileUpload'];  
echo $HTTP_POST_VARS['fileUpload'];

looks like that field is still empty. And I am attaching a screen shot of what I am uploading so you can see what i am doing.

and sorry for all the silly questions, i am totally new with PHP
thanks again!

I think you can just replace global variables with the following. However, I'm not sure whether you have correctly obtained the rest of the values. From your codes above, I can only see that you have $_POST and $_POST.

$fileName = $_POST['fileName'];  
$fileSize = $_POST['fileSize'];  
$fileDesc = $_POST['fileDesc'];  
$fileType = $_POST['fileType'];  
$fileUpload = $_POST['fileUpload'];

The file description is showing up, but nothing else.

This is what I have right now in my File_2.php....

$fileName = $_POST['fileName'];
$fileSize = $_POST['fileSize'];
$fileDescription = $_POST['fileDescription'];
$fileType = $_POST['fileType'];
$fileUpload = $_POST['fileUpload'];

echo $_POST['fileDescription<br>'];
//echo $fileName;
//echo $_POST['fileType'];
//echo $_POST['fileSize'];
echo $_POST['fileUpload']; 	//HTTP_GET_VARS['fileUpload'];  //$HTTP_POST_VARS['fileUpload'];

// Making sure both the file's location and description have been entered
	die("You didn't put the file description.<br>"); 
elseif($fileUpload == "none")
	die("You haven't selected any files.<br>"); 

// uploaded file from the local directory on the web server, and read its contents 
$fileHandle = fopen($fileUpload, "r");
$fileContent = fread($fileHandle, $fileSize);
$fileContent = addslashes($fileContent);

// Database connection set up
$dbServer = "*****.***.***.***";
$username = "*****"; 
$password = "****";  
$database = "*****";  

// connect the database using PHP's built-in MySQL functions
$mysql_access = mysql_connect($dbServer, $username, $password);
@mysql_select_db($database) or die( "Unable to connect to the database<br>"); 

//inserting values to the table
mysql_query("INSERT INTO ImageBLOB (imageID, imageDescription, imageData, imageType) VALUES (0, '$fileDescription', '$fileContent', '$fileType')");

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


seems like after trying to upload a file with description, I can connect to my database. However, when I am trying to INSERT those info to my ImageBLOB table, I get the "Couldn't add the file to database" error message. Yet, if i do the "SELECT * FROM ImageBLOB" I see that this command added one entry to the table without "imageData" & "imageType"

any suggestions please? Thank you!!

Try this:

$fileDescription = $_POST['fileDescription'];
if(empty($fileDescription)) {
die("You didn't put the file description.<br>");

$name_of_uploaded_file = basename($_FILES['fileUpload']['name']);
$type_of_uploaded_file = substr($name_of_uploaded_file, strrpos($name_of_uploaded_file, '.') + 1);

$size_of_uploaded_file = $_FILES["fileUpload"]["size"]/1024; //size in KBs

//insert into DB

note: there is no error checking.

Thank you Javvy for all your helps! i finally got it :)

$fileName = $_FILES['fileUpload']['name'];
$fileSize = $_FILES['fileUpload']['size'];
$fileType = $_FILES['fileUpload']['type'];
$tempFile = $_FILES['fileUpload']['tmp_name'];
$fileDescription = $_POST['fileDescription'];

No problem. Glad it's working and you can carry on with your work :)

You may want to mark the thread as 'solved'.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.