Re: [PHP] binary data in php

2004-04-16 Thread Lowell Allen
On Apr 15, 2004, at 11:47 PM, Anthony Ritter wrote:

John W. Holmes [EMAIL PROTECTED] wrote in message:
Remember... we're laughing with you, not at you. You forgot to call
mysql_query() in your code. :)
.

Hmmm... I wish it was as simple as that.

I inserted the mysql_query() below

but it still doesn't upload the file nor does it throw an error.

If you get a chance please take a look and advise.

Again, my thanks for your help,
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 = $_FILES['form_data']['tmp_name'];
 $uploadname = $_FILES['form_data']['name'];
 $uploadtype = $_FILES['form_data']['type'];
 $uploaddesc = $_POST['desc'];
[snip]

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

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


Re: [PHP] binary data in php

2004-04-16 Thread Anthony Ritter
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 pThis 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
pFile Description:br
input type=text name=desc size=40
INPUT TYPE=hidden name=MAX_FILE_SIZE value=100
brFile to upload/store in database:br
input type=file name=form_data size=40
pinput 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



Re: [PHP] binary data in php

2004-04-16 Thread Anthony Ritter

John W. Holmes [EMAIL PROTECTED] wrote in message:


 So what's the output? How do you know it's not working? If you're not
 getting an error, then your query is running and something is going in
 the database. Are you sure the problem isn't in how you're displaying
 the data?
..
John,
I know that there is no binary file upload to the table called binary_data
in mysql database since I checked if there was a new entry through the
command line after I submit.

After I hit submit, the field that I inserted are blank.

Any other thoughts?

Thank you for your time.
TR

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



Re: [PHP] binary data in php

2004-04-16 Thread Jason Wong
On Friday 16 April 2004 20:35, Anthony Ritter wrote:

 I know that there is no binary file upload to the table called binary_data
 in mysql database since I checked if there was a new entry through the
 command line after I submit.

 After I hit submit, the field that I inserted are blank.

 Any other thoughts?

You have two possible problems here:

1) The file upload is not working properly
2) The file is uploaded but is not inserted

Find out what your problem is and take it from there. If you don't know how to 
determine your problem:

manual  Error Handling and Logging Functions
print_r()
var_dump()

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Pie are not square.  Pie are round.  Cornbread are square.
*/

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



Re: [PHP] binary data in php

2004-04-16 Thread Marek Kilimajer
Anthony Ritter wrote:
Any other thoughts?

Best...
TR
...
?
 if ($submit) {
You said register globals are off, didn't you? Where is the above 
variable set then?

:)

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


Re: [PHP] binary data in php

2004-04-16 Thread Anthony Ritter
Marek Kilimajer [EMAIL PROTECTED] wrote in message:

 You said register globals are off, didn't you? Where is the above
 variable set then?

 :)
...

That was it.

Many thanks Marek and others.

Checking through the command line the file was uploaded to mysql database.

However when clicking the getdata.php link - the file does not appear on the
screen.

The code is below.

Thank you for your time.
TR
.

//getdata.php

?
if($_GET['id']==1) {
@myql_connect(localhost,root,mypass);
@mysql_select_db(sitename);
$query = SELECT bin_data,description,filetype
  FROM binary_data
  WHERE id=1;
$result = @mysql_query($query);
$data = @mysql_result($result,0,bin_data);
$description = @mysql_result($result,0,description);
$type = @mysql_result($result,0,filetype);
Header( Content-type: $type);
echo $data.br;
echo $description.br;
}
else
 {

@mysql_connect(localhost,root,mypass);
@mysql_select_db(sitename);
$query = SELECT bin_data,description,filetype
  FROM binary_data
  WHERE id=$id;
$result = @mysql_query($query);
$data = @mysql_result($result,0,bin_data);
$description = @mysql_result($result,0,description);
$type = @mysql_result($result,0,filetype);
Header( Content-type: $type);
echo $data.br;
echo $description.br;
}
?

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



Re: [PHP] binary data in php

2004-04-16 Thread Marek Kilimajer
Anthony Ritter wrote:
However when clicking the getdata.php link - the file does not appear on the
screen.
The code is below.

Thank you for your time.
TR
.
//getdata.php

?
if($_GET['id']==1) {
@myql_connect(localhost,root,mypass);
Remove @'s while debugging.

@mysql_select_db(sitename);
$query = SELECT bin_data,description,filetype
  FROM binary_data
  WHERE id=1;
$result = @mysql_query($query);
$data = @mysql_result($result,0,bin_data);
$description = @mysql_result($result,0,description);
$type = @mysql_result($result,0,filetype);
Header( Content-type: $type);
echo $data.br;
echo $description.br;
The above cannot work. You cannot mix binary data with html.

}
else
 {
@mysql_connect(localhost,root,mypass);
@mysql_select_db(sitename);
$query = SELECT bin_data,description,filetype
  FROM binary_data
  WHERE id=$id;
--^^
register globals are off, and the variable is not validated - can 
contain anything

$result = @mysql_query($query);
$data = @mysql_result($result,0,bin_data);
$description = @mysql_result($result,0,description);
$type = @mysql_result($result,0,filetype);
Header( Content-type: $type);
echo $data.br;
echo $description.br;
}
?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] binary data in php

2004-04-15 Thread Anthony Ritter
Greets,
Register globals are to off - however the files will not upload.

At wit's end - help please!

Thank all in advance.

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 = $_FILES['form_data']['tmp_name'];
 $uploadname = $_FILES['form_data']['name'];
 $uploadtype = $_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';

   $id= mysql_insert_id();

   print pThis 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
pFile Description:br
input type=text name=desc size=40
INPUT TYPE=hidden name=MAX_FILE_SIZE value=100
brFile to upload/store in database:br
input type=file name=form_data size=40
pinput 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



Re: [PHP] binary data in php

2004-04-15 Thread John W. Holmes
Anthony Ritter wrote:

Greets,
Register globals are to off - however the files will not upload.
At wit's end - help please!

Thank all in advance.

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 = $_FILES['form_data']['tmp_name'];
 $uploadname = $_FILES['form_data']['name'];
 $uploadtype = $_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';
   $id= mysql_insert_id();

   print pThis 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
pFile Description:br
input type=text name=desc size=40
INPUT TYPE=hidden name=MAX_FILE_SIZE value=100
brFile to upload/store in database:br
input type=file name=form_data size=40
pinput type=submit name=submit value=submit
/form
?php
}
?
Remember... we're laughing with you, not at you. You forgot to call 
mysql_query() in your code. :)

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] binary data in php

2004-04-15 Thread Anthony Ritter
John W. Holmes [EMAIL PROTECTED] wrote in message:
 Remember... we're laughing with you, not at you. You forgot to call
 mysql_query() in your code. :)
.

Hmmm... I wish it was as simple as that.

I inserted the mysql_query() below

but it still doesn't upload the file nor does it throw an error.

If you get a chance please take a look and advise.

Again, my thanks for your help,
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 = $_FILES['form_data']['tmp_name'];
 $uploadname = $_FILES['form_data']['name'];
 $uploadtype = $_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 pThis 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
pFile Description:br
input type=text name=desc size=40
INPUT TYPE=hidden name=MAX_FILE_SIZE value=100
brFile to upload/store in database:br
input type=file name=form_data size=40
pinput 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



Re: [PHP] binary data in php

2004-04-15 Thread John W. Holmes
Anthony Ritter wrote:

I inserted the mysql_query() below

but it still doesn't upload the file nor does it throw an error.
[snip]
// 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 pThis 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();
So what's the output? How do you know it's not working? If you're not 
getting an error, then your query is running and something is going in 
the database. Are you sure the problem isn't in how you're displaying 
the data?

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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