passing values with PHP in Apache

A

Anonymous

Guest
ok here's the problem. pages do not seem to be echoing variables

Code:
<?php

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

// Make sure there is a description and a file path entered

if(empty($strDesc) || $fileUpload=="none")
die("You must enter both a description and file");

// Database connection variables
$dbServer="localhost";
$dbDatabase="thedatabase";
$dbUser="user";
$dbPass="pass";

$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 myBlobs VALUES";
$dbQuery .= "(0, '$strDesc', '$fileContent', '$fileUpload_type')";

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

?>

when i post to this PHP file from the following form I get the error "You must enter both a description and file"

Code:
<html>
<head><title>Upload files here</title></head>

<body>

<form enctype="multipart/form-data" name="frmUploadFile" action="grabfile.php" method="post">
<input type="text" name="strDesc" size="20" maxlength="50" /><br />
<input type="file" name="fileUpload" size="20"> <br/>
<input type="submit" name="cmdSubmit" value="Upload"><br />
</form>

</body>
</html>

This code works as is one my University's server. When the same code is executed on my server it does not do what it should. The problem is that the page is not getting the variables. Any ideas anyone? I'm wondering if there is some configuration that I need to change. FYI I'm running Fedora Core 4 with Apache and PHP4

Thanks in advanced. Any suggestions would be greatly appreciated.
 
Try using $_POST superglobal variable.
Your school server probably have PHP's register_globals directive set to On.
So seems that you have it Off in your server (and that's the best option - for security reasons).
So... you will now need to use the superglobal variables.

Example:
Code:
<?php

$strDesc = $_POST['strDesc'];
$fileUpload = $_POST['fileUpload'];
$fileUpload_name = $_POST['fileUpload_name'];
$fileUpload_size = $_POST['fileUpload_size'];
$fileUpload_type = $_POST['fileUpload_type'];

// The rest like it is

?>
 
Back
Top