Lowell Allen <[EMAIL PROTECTED]> wrote in message:

> You might try using "$HTTP_POST_FILES" rather than "$_FILES" -- was
> necessary in my code recently.
>
> --
> Lowell Allen
...................

Lowell,
Thank you.

I tried that in code below.

Still - no dice.

Any other thoughts?

Best...
TR
...............

<?
 if ($submit) {

// connect to the database
// (you may have to adjust the hostname,username or password)

mysql_connect("localhost","root","mypass");
mysql_select_db("mydb");

 $uploadfile = $HTTP_POST_FILES['form_data']['tmp_name'];
 $uploadname = $HTTP_POST_FILES['form_data']['name'];
 $uploadtype = $HTTP_POST_FILES['form_data']['type'];
 $uploaddesc = $_POST['desc'];

        // Open file for binary reading ('rb')
 $tempfile = fopen($uploadfile,'rb');

  // Read the entire file into memory using PHP's
 // filesize function to get the file size.
 $filedata = fread($tempfile,filesize($uploadfile));

        // Prepare for database insert by adding backslashes
 // before special characters.
 $filedata = addslashes($filedata);

        // Create the SQL query.
 $sql = "INSERT INTO binary_data SET
  filename = '$uploadname',
  filetype = '$uploadtype',
  description = '$uploaddesc',
  bin_data = '$filedata'";

 $ok = @mysql_query($sql);

 if(!$ok)die('Database error storing the file:'.mysql_error());

 $id= mysql_insert_id();


       print "<p>This file has the following Database ID: <b>$id</b>";
       echo "<br>";
       echo "<a href=\"getdata.php?id=$id\">Click to view file</a>";
       MYSQL_CLOSE();

} else {

// else show the form to submit new data:
?>

<form method="post" action="<?php echo $PHP_SELF; ?>"
enctype="multipart/form-data">
<p>File Description:<br>
<input type="text" name="desc" size="40">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload/store in database:<br>
<input type="file" name="form_data" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to