file upload to database help
- virose
- Novice


- Joined: Jul 20, 2005
- Posts: 27
- Loc: florida
- Status: Offline
Hello Guys,
Any help with this would be greatly appreciated
It appears to be connecting fine. my problem is i cant get the upload code to insert a file into the database.
I cant locate the issue with the code i have ran it on a test server as well as on my main servers.
I have double tipple checked the DB names and TABLE name the one on this are dummy the problem i think is in the logic somewhere.
This is the connect to database code
this is the upload code
Thanks, Again
Any help with this would be greatly appreciated
It appears to be connecting fine. my problem is i cant get the upload code to insert a file into the database.
I cant locate the issue with the code i have ran it on a test server as well as on my main servers.
I have double tipple checked the DB names and TABLE name the one on this are dummy the problem i think is in the logic somewhere.
This is the connect to database code
Code: [ Select ]
<?php
$db = mysql_connect("localhost", "binary_user", "binary_password");
mysql_select_db("binary_files", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
?>
$db = mysql_connect("localhost", "binary_user", "binary_password");
mysql_select_db("binary_files", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
?>
- <?php
- $db = mysql_connect("localhost", "binary_user", "binary_password");
- mysql_select_db("binary_files", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
- ?>
this is the upload code
Code: [ Select ]
<?php
if ($action == "upload") {
// ok, let's get the uploaded data and insert it into the db now
include "open_db.inc";
if (isset($binFile) && $binFile != "none") {
$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO tbl_Files ";
$sql .= "(description, bin_data, filename, filesize, filetype) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
$result = mysql_query($sql, $db);
mysql_free_result($result); // it's always nice to clean up!
echo "Thank you. The new file was successfully added to our database.<br><br>";
echo "<a href='main.php'>Continue</a>";
}
mysql_close();
} else {
?>
<HTML>
<BODY>
<FORM METHOD="post" ACTION="add.php" ENCTYPE="multipart/form-data">
<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="1000000">
<INPUT TYPE="hidden" NAME="action" VALUE="upload">
<TABLE BORDER="1">
<TR>
<TD>Description: </TD>
<TD><TEXTAREA NAME="txtDescription" ROWS="10" COLS="50"></TEXTAREA></TD>
</TR>
<TR>
<TD>File: </TD>
<TD><INPUT TYPE="file" NAME="binFile"></TD>
</TR>
<TR>
<TD COLSPAN="2"><INPUT TYPE="submit" VALUE="Upload"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
<?php
}
?>
if ($action == "upload") {
// ok, let's get the uploaded data and insert it into the db now
include "open_db.inc";
if (isset($binFile) && $binFile != "none") {
$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO tbl_Files ";
$sql .= "(description, bin_data, filename, filesize, filetype) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
$result = mysql_query($sql, $db);
mysql_free_result($result); // it's always nice to clean up!
echo "Thank you. The new file was successfully added to our database.<br><br>";
echo "<a href='main.php'>Continue</a>";
}
mysql_close();
} else {
?>
<HTML>
<BODY>
<FORM METHOD="post" ACTION="add.php" ENCTYPE="multipart/form-data">
<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="1000000">
<INPUT TYPE="hidden" NAME="action" VALUE="upload">
<TABLE BORDER="1">
<TR>
<TD>Description: </TD>
<TD><TEXTAREA NAME="txtDescription" ROWS="10" COLS="50"></TEXTAREA></TD>
</TR>
<TR>
<TD>File: </TD>
<TD><INPUT TYPE="file" NAME="binFile"></TD>
</TR>
<TR>
<TD COLSPAN="2"><INPUT TYPE="submit" VALUE="Upload"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
<?php
}
?>
- <?php
- if ($action == "upload") {
- // ok, let's get the uploaded data and insert it into the db now
- include "open_db.inc";
- if (isset($binFile) && $binFile != "none") {
- $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
- $strDescription = addslashes(nl2br($txtDescription));
- $sql = "INSERT INTO tbl_Files ";
- $sql .= "(description, bin_data, filename, filesize, filetype) ";
- $sql .= "VALUES ('$strDescription', '$data', ";
- $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
- $result = mysql_query($sql, $db);
- mysql_free_result($result); // it's always nice to clean up!
- echo "Thank you. The new file was successfully added to our database.<br><br>";
- echo "<a href='main.php'>Continue</a>";
- }
- mysql_close();
- } else {
- ?>
- <HTML>
- <BODY>
- <FORM METHOD="post" ACTION="add.php" ENCTYPE="multipart/form-data">
- <INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="1000000">
- <INPUT TYPE="hidden" NAME="action" VALUE="upload">
- <TABLE BORDER="1">
- <TR>
- <TD>Description: </TD>
- <TD><TEXTAREA NAME="txtDescription" ROWS="10" COLS="50"></TEXTAREA></TD>
- </TR>
- <TR>
- <TD>File: </TD>
- <TD><INPUT TYPE="file" NAME="binFile"></TD>
- </TR>
- <TR>
- <TD COLSPAN="2"><INPUT TYPE="submit" VALUE="Upload"></TD>
- </TR>
- </TABLE>
- </FORM>
- </BODY>
- </HTML>
- <?php
- }
- ?>
Thanks, Again
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
May 4th, 2009, 8:57 am
- Bogey
- Bogey


- Joined: Jul 14, 2005
- Posts: 8211
- Loc: USA
- Status: Offline
Try the following and see what you will get:
PHP Code: [ Select ]
<?php
if ($action == "upload")
{
// ok, let's get the uploaded data and insert it into the db now
include "open_db.inc";
if (isset($binFile) && $binFile != "none")
{
$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO tbl_Files ";
$sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
if($result = mysql_query($sql, $db))
{
echo "Thank you. The new file was successfully added to our database.<br><br>";
}
else
{
echo "There was a problem with adding the file to our database.<br /><br />";
die(mysql_error());
}
mysql_free_result($result); // it's always nice to clean up!
echo "<a href='main.php'>Continue</a>";
}
mysql_close();
}
?>
if ($action == "upload")
{
// ok, let's get the uploaded data and insert it into the db now
include "open_db.inc";
if (isset($binFile) && $binFile != "none")
{
$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO tbl_Files ";
$sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
if($result = mysql_query($sql, $db))
{
echo "Thank you. The new file was successfully added to our database.<br><br>";
}
else
{
echo "There was a problem with adding the file to our database.<br /><br />";
die(mysql_error());
}
mysql_free_result($result); // it's always nice to clean up!
echo "<a href='main.php'>Continue</a>";
}
mysql_close();
}
?>
- <?php
- if ($action == "upload")
- {
- // ok, let's get the uploaded data and insert it into the db now
- include "open_db.inc";
- if (isset($binFile) && $binFile != "none")
- {
- $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
- $strDescription = addslashes(nl2br($txtDescription));
- $sql = "INSERT INTO tbl_Files ";
- $sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
- $sql .= "VALUES ('$strDescription', '$data', ";
- $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
- if($result = mysql_query($sql, $db))
- {
- echo "Thank you. The new file was successfully added to our database.<br><br>";
- }
- else
- {
- echo "There was a problem with adding the file to our database.<br /><br />";
- die(mysql_error());
- }
- mysql_free_result($result); // it's always nice to clean up!
- echo "<a href='main.php'>Continue</a>";
- }
- mysql_close();
- }
- ?>
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
- dark_lord
- Graduate


- Joined: Jan 14, 2009
- Posts: 162
- Loc: India-Kolkata
- Status: Offline
do you have the globals on?
if not then you should have problem, to work around that, you must change
$binFile_name, $binFile_size, $binFile_type
try this
maybe you have globals on and having problem with SQL.
Firstly, it is not cleared that if you are inserting the whole file into the database or inserting the file name into the database?
The above code is for file name to be inserted. If you want to insert the whole file, then the above code will be different!!
if not then you should have problem, to work around that, you must change
$binFile_name, $binFile_size, $binFile_type
try this
Code: [ Select ]
<?php
if ($action == "upload")
{
// ok, let's get the uploaded data and insert it into the db now
include "open_db.inc";
if (isset($binFile) && $binFile != "none")
{
$binFile_name = $_FILES['binFile_name']['name'];
$binFile_size = $_FILES['binFile_name']['size'];
$binFile_type = $_FILES['binFile_name']['type'];
$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO tbl_Files ";
$sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
if($result = mysql_query($sql, $db))
{
echo "Thank you. The new file was successfully added to our database.<br><br>";
}
else
{
echo "There was a problem with adding the file to our database.<br /><br />";
die(mysql_error());
}
mysql_free_result($result); // it's always nice to clean up!
echo "<a href='main.php'>Continue</a>";
}
mysql_close();
}
?>
if ($action == "upload")
{
// ok, let's get the uploaded data and insert it into the db now
include "open_db.inc";
if (isset($binFile) && $binFile != "none")
{
$binFile_name = $_FILES['binFile_name']['name'];
$binFile_size = $_FILES['binFile_name']['size'];
$binFile_type = $_FILES['binFile_name']['type'];
$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO tbl_Files ";
$sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
if($result = mysql_query($sql, $db))
{
echo "Thank you. The new file was successfully added to our database.<br><br>";
}
else
{
echo "There was a problem with adding the file to our database.<br /><br />";
die(mysql_error());
}
mysql_free_result($result); // it's always nice to clean up!
echo "<a href='main.php'>Continue</a>";
}
mysql_close();
}
?>
- <?php
- if ($action == "upload")
- {
- // ok, let's get the uploaded data and insert it into the db now
- include "open_db.inc";
- if (isset($binFile) && $binFile != "none")
- {
- $binFile_name = $_FILES['binFile_name']['name'];
- $binFile_size = $_FILES['binFile_name']['size'];
- $binFile_type = $_FILES['binFile_name']['type'];
- $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
- $strDescription = addslashes(nl2br($txtDescription));
- $sql = "INSERT INTO tbl_Files ";
- $sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
- $sql .= "VALUES ('$strDescription', '$data', ";
- $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
- if($result = mysql_query($sql, $db))
- {
- echo "Thank you. The new file was successfully added to our database.<br><br>";
- }
- else
- {
- echo "There was a problem with adding the file to our database.<br /><br />";
- die(mysql_error());
- }
- mysql_free_result($result); // it's always nice to clean up!
- echo "<a href='main.php'>Continue</a>";
- }
- mysql_close();
- }
- ?>
maybe you have globals on and having problem with SQL.
Firstly, it is not cleared that if you are inserting the whole file into the database or inserting the file name into the database?
The above code is for file name to be inserted. If you want to insert the whole file, then the above code will be different!!
Wrap Up your Big Url | Mariana World Community
- Bogey
- Bogey


- Joined: Jul 14, 2005
- Posts: 8211
- Loc: USA
- Status: Offline
Code: [ Select ]
$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO tbl_Files ";
$sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO tbl_Files ";
$sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
- $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
- $strDescription = addslashes(nl2br($txtDescription));
- $sql = "INSERT INTO tbl_Files ";
- $sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
- $sql .= "VALUES ('$strDescription', '$data', ";
- $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
I'm sure he is putting the contents of the file into it.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
- virose
- Novice


- Joined: Jul 20, 2005
- Posts: 27
- Loc: florida
- Status: Offline
Bogey wrote:
Try the following and see what you will get:
PHP Code: [ Select ]
<?php
if ($action == "upload")
{
// ok, let's get the uploaded data and insert it into the db now
include "open_db.inc";
if (isset($binFile) && $binFile != "none")
{
$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO tbl_Files ";
$sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
if($result = mysql_query($sql, $db))
{
echo "Thank you. The new file was successfully added to our database.<br><br>";
}
else
{
echo "There was a problem with adding the file to our database.<br /><br />";
die(mysql_error());
}
mysql_free_result($result); // it's always nice to clean up!
echo "<a href='main.php'>Continue</a>";
}
mysql_close();
}
?>
if ($action == "upload")
{
// ok, let's get the uploaded data and insert it into the db now
include "open_db.inc";
if (isset($binFile) && $binFile != "none")
{
$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO tbl_Files ";
$sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
if($result = mysql_query($sql, $db))
{
echo "Thank you. The new file was successfully added to our database.<br><br>";
}
else
{
echo "There was a problem with adding the file to our database.<br /><br />";
die(mysql_error());
}
mysql_free_result($result); // it's always nice to clean up!
echo "<a href='main.php'>Continue</a>";
}
mysql_close();
}
?>
- <?php
- if ($action == "upload")
- {
- // ok, let's get the uploaded data and insert it into the db now
- include "open_db.inc";
- if (isset($binFile) && $binFile != "none")
- {
- $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
- $strDescription = addslashes(nl2br($txtDescription));
- $sql = "INSERT INTO tbl_Files ";
- $sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
- $sql .= "VALUES ('$strDescription', '$data', ";
- $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
- if($result = mysql_query($sql, $db))
- {
- echo "Thank you. The new file was successfully added to our database.<br><br>";
- }
- else
- {
- echo "There was a problem with adding the file to our database.<br /><br />";
- die(mysql_error());
- }
- mysql_free_result($result); // it's always nice to clean up!
- echo "<a href='main.php'>Continue</a>";
- }
- mysql_close();
- }
- ?>
this is the errors i get with this code block, Thanks for the help. Any more help greatly appreciated. Because i don't understand what is wrong with this code.
ERORRS
$db = mysql_connect("localhost", "jason", "jason"); mysql_select_db("my_family", $db) or die(mysql_errno() . ": " . mysql_error() . "
");
Notice: Undefined variable: db in H:\wamp\www\php_testing\add.php on line 15
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in H:\wamp\www\php_testing\add.php on line 15
There was a problem with adding the file to our database.
END ERRORS
- virose
- Novice


- Joined: Jul 20, 2005
- Posts: 27
- Loc: florida
- Status: Offline
dark_lord wrote:
do you have the globals on?
if not then you should have problem, to work around that, you must change
$binFile_name, $binFile_size, $binFile_type
try this
<?php
if ($action == "upload")
{
// ok, let's get the uploaded data and insert it into the db now
include "open_db.inc";
if (isset($binFile) && $binFile != "none")
{
$binFile_name = $_FILES['binFile_name']['name'];
$binFile_size = $_FILES['binFile_name']['size'];
$binFile_type = $_FILES['binFile_name']['type'];
$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO tbl_Files ";
$sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
if($result = mysql_query($sql, $db))
{
echo "Thank you. The new file was successfully added to our database.<br><br>";
}
else
{
echo "There was a problem with adding the file to our database.<br /><br />";
die(mysql_error());
}
mysql_free_result($result); // it's always nice to clean up!
echo "<a href='main.php'>Continue</a>";
}
mysql_close();
}
?>
maybe you have globals on and having problem with SQL.
Firstly, it is not cleared that if you are inserting the whole file into the database or inserting the file name into the database?
The above code is for file name to be inserted. If you want to insert the whole file, then the above code will be different!!
if not then you should have problem, to work around that, you must change
$binFile_name, $binFile_size, $binFile_type
try this
Code: [ Select ]
<?php
if ($action == "upload")
{
// ok, let's get the uploaded data and insert it into the db now
include "open_db.inc";
if (isset($binFile) && $binFile != "none")
{
$binFile_name = $_FILES['binFile_name']['name'];
$binFile_size = $_FILES['binFile_name']['size'];
$binFile_type = $_FILES['binFile_name']['type'];
$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO tbl_Files ";
$sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
if($result = mysql_query($sql, $db))
{
echo "Thank you. The new file was successfully added to our database.<br><br>";
}
else
{
echo "There was a problem with adding the file to our database.<br /><br />";
die(mysql_error());
}
mysql_free_result($result); // it's always nice to clean up!
echo "<a href='main.php'>Continue</a>";
}
mysql_close();
}
?>
- <?php
- if ($action == "upload")
- {
- // ok, let's get the uploaded data and insert it into the db now
- include "open_db.inc";
- if (isset($binFile) && $binFile != "none")
- {
- $binFile_name = $_FILES['binFile_name']['name'];
- $binFile_size = $_FILES['binFile_name']['size'];
- $binFile_type = $_FILES['binFile_name']['type'];
- $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
- $strDescription = addslashes(nl2br($txtDescription));
- $sql = "INSERT INTO tbl_Files ";
- $sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
- $sql .= "VALUES ('$strDescription', '$data', ";
- $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
- if($result = mysql_query($sql, $db))
- {
- echo "Thank you. The new file was successfully added to our database.<br><br>";
- }
- else
- {
- echo "There was a problem with adding the file to our database.<br /><br />";
- die(mysql_error());
- }
- mysql_free_result($result); // it's always nice to clean up!
- echo "<a href='main.php'>Continue</a>";
- }
- mysql_close();
- }
- ?>
maybe you have globals on and having problem with SQL.
Firstly, it is not cleared that if you are inserting the whole file into the database or inserting the file name into the database?
The above code is for file name to be inserted. If you want to insert the whole file, then the above code will be different!!
This code block produced these erorrs. thanks for the help.
and yes to clarify I am inserting the whole file into a database using the mediumblob setting.
ERRORS
$db = mysql_connect("localhost", "jason", "jason"); mysql_select_db("my_family", $db) or die(mysql_errno() . ": " . mysql_error() . "
");
Notice: Undefined index: binFile_name in H:\wamp\www\php_testing\add.php on line 9
Notice: Undefined index: binFile_name in H:\wamp\www\php_testing\add.php on line 10
Notice: Undefined index: binFile_name in H:\wamp\www\php_testing\add.php on line 11
Notice: Undefined variable: db in H:\wamp\www\php_testing\add.php on line 18
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in H:\wamp\www\php_testing\add.php on line 18
There was a problem with adding the file to our database.
END ERRORS
- Bogey
- Bogey


- Joined: Jul 14, 2005
- Posts: 8211
- Loc: USA
- Status: Offline
- virose
- Novice


- Joined: Jul 20, 2005
- Posts: 27
- Loc: florida
- Status: Offline
Hey Bogey,
Thanks for the help on that one, I got it working now. Global's was off for one thing which was causing problems.
And then i had a small issue with my connect code.
I'm not worried about passwords it just a test server on a test pc.
Now the download file is not working.
Think you can help out?
Here is the code if so.
Here are the errors i get.
ERRORS
Notice: Undefined variable: id_files in H:\wamp\www\php_testing\download.php on line 2
ERORR IN CODE
END ERRORS
Thanks for the help on that one, I got it working now. Global's was off for one thing which was causing problems.
And then i had a small issue with my connect code.
I'm not worried about passwords it just a test server on a test pc.
Now the download file is not working.
Think you can help out?
Here is the code if so.
Code: [ Select ]
<?php
if ($id_files) {
include "open_db.inc";
$sql = "SELECT bin_data, filetype, filename, filesize FROM family_pics WHERE id_file=$id_files";
$result = @mysql_query($sql, $db);
$data = @mysql_result($result, 0, "bin_data");
$name = @mysql_result($result, 0, "filename");
$size = @mysql_result($result, 0, "filesize");
$type = @mysql_result($result, 0, "filetype");
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
} else { echo 'ERORR IN CODE';}
?>
if ($id_files) {
include "open_db.inc";
$sql = "SELECT bin_data, filetype, filename, filesize FROM family_pics WHERE id_file=$id_files";
$result = @mysql_query($sql, $db);
$data = @mysql_result($result, 0, "bin_data");
$name = @mysql_result($result, 0, "filename");
$size = @mysql_result($result, 0, "filesize");
$type = @mysql_result($result, 0, "filetype");
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
} else { echo 'ERORR IN CODE';}
?>
- <?php
- if ($id_files) {
- include "open_db.inc";
- $sql = "SELECT bin_data, filetype, filename, filesize FROM family_pics WHERE id_file=$id_files";
- $result = @mysql_query($sql, $db);
- $data = @mysql_result($result, 0, "bin_data");
- $name = @mysql_result($result, 0, "filename");
- $size = @mysql_result($result, 0, "filesize");
- $type = @mysql_result($result, 0, "filetype");
- header("Content-type: $type");
- header("Content-length: $size");
- header("Content-Disposition: attachment; filename=$name");
- header("Content-Description: PHP Generated Data");
- echo $data;
- } else { echo 'ERORR IN CODE';}
- ?>
Here are the errors i get.
ERRORS
Notice: Undefined variable: id_files in H:\wamp\www\php_testing\download.php on line 2
ERORR IN CODE
END ERRORS
- Bogey
- Bogey


- Joined: Jul 14, 2005
- Posts: 8211
- Loc: USA
- Status: Offline
- virose
- Novice


- Joined: Jul 20, 2005
- Posts: 27
- Loc: florida
- Status: Offline
- Bogey
- Bogey


- Joined: Jul 14, 2005
- Posts: 8211
- Loc: USA
- Status: Offline
- Bogey
- Bogey


- Joined: Jul 14, 2005
- Posts: 8211
- Loc: USA
- Status: Offline
Also why are you doing:
...?
Why not:
Or just use $row['field'] instead of setting variables.
Code: [ Select ]
$data = @mysql_result($result, 0, "bin_data");
$name = @mysql_result($result, 0, "filename");
$size = @mysql_result($result, 0, "filesize");
$type = @mysql_result($result, 0, "filetype");
$name = @mysql_result($result, 0, "filename");
$size = @mysql_result($result, 0, "filesize");
$type = @mysql_result($result, 0, "filetype");
- $data = @mysql_result($result, 0, "bin_data");
- $name = @mysql_result($result, 0, "filename");
- $size = @mysql_result($result, 0, "filesize");
- $type = @mysql_result($result, 0, "filetype");
...?
Why not:
Code: [ Select ]
$row = mysql_fetch_assoc($result);
$data = $row['bin_data'];
$name = $row['filename'];
$size = $row['filesize'];
$type = $row['filetype'];
$data = $row['bin_data'];
$name = $row['filename'];
$size = $row['filesize'];
$type = $row['filetype'];
- $row = mysql_fetch_assoc($result);
- $data = $row['bin_data'];
- $name = $row['filename'];
- $size = $row['filesize'];
- $type = $row['filetype'];
Or just use $row['field'] instead of setting variables.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
- virose
- Novice


- Joined: Jul 20, 2005
- Posts: 27
- Loc: florida
- Status: Offline
- virose
- Novice


- Joined: Jul 20, 2005
- Posts: 27
- Loc: florida
- Status: Offline
Ok here's where i am with the download code.
What is the best way to define the var id_files, so the code will just spit the file to the browser for download.
I know now that the variable just needs to be defined, i'm just not sure how to define it and make the if statement still work correctly.
Thanks in advance.
Jason
<?php
if ($id_files) {
include "open_db.inc";
$sql = "SELECT bin_data, filetype, filename, filesize FROM family_pics WHERE id_file=$id_files";
$result = @mysql_query($sql, $db);
$row = mysql_fetch_assoc($result);
$data = $row['bin_data'];
$name = $row['filename'];
$size = $row['filesize'];
$type = $row['filetype'];
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
} else { echo 'ERORR IN CODE';}
?>
What is the best way to define the var id_files, so the code will just spit the file to the browser for download.
I know now that the variable just needs to be defined, i'm just not sure how to define it and make the if statement still work correctly.
Thanks in advance.
Jason
Code: [ Select ]
<?php
if ($id_files) {
include "open_db.inc";
$sql = "SELECT bin_data, filetype, filename, filesize FROM family_pics WHERE id_file=$id_files";
$result = @mysql_query($sql, $db);
$row = mysql_fetch_assoc($result);
$data = $row['bin_data'];
$name = $row['filename'];
$size = $row['filesize'];
$type = $row['filetype'];
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
} else { echo 'ERORR IN CODE';}
?>
- <?php
- if ($id_files) {
- include "open_db.inc";
- $sql = "SELECT bin_data, filetype, filename, filesize FROM family_pics WHERE id_file=$id_files";
- $result = @mysql_query($sql, $db);
- $row = mysql_fetch_assoc($result);
- $data = $row['bin_data'];
- $name = $row['filename'];
- $size = $row['filesize'];
- $type = $row['filetype'];
- header("Content-type: $type");
- header("Content-length: $size");
- header("Content-Disposition: attachment; filename=$name");
- header("Content-Description: PHP Generated Data");
- echo $data;
- } else { echo 'ERORR IN CODE';}
- ?>
- Bogey
- Bogey


- Joined: Jul 14, 2005
- Posts: 8211
- Loc: USA
- Status: Offline
Code: [ Select ]
<?php
$id_files = 17;
if ($id_files) {
include "open_db.inc";
$sql = "SELECT bin_data, filetype, filename, filesize FROM family_pics WHERE id_file=$id_files";
$result = @mysql_query($sql, $db);
$row = mysql_fetch_assoc($result);
$data = $row['bin_data'];
$name = $row['filename'];
$size = $row['filesize'];
$type = $row['filetype'];
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
} else { echo 'ERORR IN CODE';}
?>
$id_files = 17;
if ($id_files) {
include "open_db.inc";
$sql = "SELECT bin_data, filetype, filename, filesize FROM family_pics WHERE id_file=$id_files";
$result = @mysql_query($sql, $db);
$row = mysql_fetch_assoc($result);
$data = $row['bin_data'];
$name = $row['filename'];
$size = $row['filesize'];
$type = $row['filetype'];
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
} else { echo 'ERORR IN CODE';}
?>
- <?php
- $id_files = 17;
- if ($id_files) {
- include "open_db.inc";
- $sql = "SELECT bin_data, filetype, filename, filesize FROM family_pics WHERE id_file=$id_files";
- $result = @mysql_query($sql, $db);
- $row = mysql_fetch_assoc($result);
- $data = $row['bin_data'];
- $name = $row['filename'];
- $size = $row['filesize'];
- $type = $row['filetype'];
- header("Content-type: $type");
- header("Content-length: $size");
- header("Content-Disposition: attachment; filename=$name");
- header("Content-Description: PHP Generated Data");
- echo $data;
- } else { echo 'ERORR IN CODE';}
- ?>
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
May 11th, 2009, 5:58 pm
1, 2
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 22 posts
- Users browsing this forum: No registered users and 157 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
