Results 1 to 3 of 3

Thread: PHP5 Blobs

  1. #1
    Join Date
    Jul 2009
    Posts
    2

    Unanswered: 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>";

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    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 on the Tiger 800 or the Norton

  3. #3
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •