If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > PHP5 Blobs

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-20-09, 11:22
whiteyoh whiteyoh is offline
Registered User
 
Join Date: Jul 2009
Posts: 2
PHP5 Blobs

Hi all,

The following script is for uploading a file as a blob to a mysql database. The first is the form, which asks you to give a description and to select a file.

On clicking to upload it is stating that i have not given a description or selected a file. I have done my best to find the issue (maybe a capital letter or something, but im a bit baffled

Code:
<title> Upload a File </title>
<form enctype="multipart/form-data" name="frmUploadFile" action="grabfile.php" method="post">
Upload a File
<br>Please select a file to upload </p>


File Description:		<input type="text" name="strDesc" size="20" maxlength="50"> <br />
File Location:			<input type="file" name="fileUpload" size="20"></font></td><br />
							
							<input type="submit" value="Upload this file" name="cmdSubmit"></font>

</form>
Code:
<?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(isset($strDesc) || $fileUpload == "none")

die("You must enter both a description and file");
// Database connection variables

$dbServer = "localhost";

$dbDatabase = "localhost";

$dbUser = "whitep8";

$dbPass = "pw002f1945";
$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");
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>";
Reply With Quote
  #2 (permalink)  
Old 07-20-09, 14:29
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
most likely is that the $Request or $Post variables haven't been configured as "auto on" in the PHP INI script, which is fair enough as it seen as bad practice and a potential security breach

So instead encapsulate the variables that you use in your script with
$_POST["MyVaraiableName"]
$_REQUEST["MyVaraiableName"]
or
$_GET["MyVaraiableName"]
...depending what variable you want to use
PHP Code:
if(isset($_POST["strDesc"]) || $_POST["$fileUpload"] == "none"
I think you can import the $Post & $Request variables so you can use without the prefix $_POST[" or $_REQUEST[" but thats depracated
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 07-21-09, 04:50
whiteyoh whiteyoh is offline
Registered User
 
Join Date: Jul 2009
Posts: 2
php blobs

Hi,

I have tried your suggestion but to no avail. I cant help think theres something wrong with the main firm, not the php.

Curious
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On