Page 1 of 1

Uploading and downloading files

Posted: Fri Jul 28, 2006 10:26 am
by janculis
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi!
I have some problem.
I want create a nice home page, where people can upload some file and it download.
So I wanted to insert these files in DB.
But my code does not working.
I cannot insert into database file.

So...
My code is here:

Code: Select all

<?php
if ($action == "upload") {
include "open_db.inc"; <--works

$txtDescription= $_POST['txtDescription'];
$binFile= $_POST['binFile'];

if (isset($binFile) && $binFile != "") {
$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO tbl_Files (
description,
bin_data,
filename,
filesize,
filetype)
VALUES (
'$strDescription',
'$data',
'$binFile_name',
'$binFile_size',
'$binFile_type')";
$result = mysql_query($sql, $db);
mysql_free_result($result);
if(!$result) {die('Neievietoja datus:' .mysql_error());}
echo "Jauns ieraksts pievienots.";
echo "Thank you. The new file was successfully added to our database.<br><br>";
echo "<a href='main.php'>Continue</a>";
}
mysql_close();

} else {
?>

<BODY>
<FORM METHOD="post" ACTION="<?php echo $PHP_SELF;?>" 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>

<?php
}
?>
In the file open_db.inc everything is OK. When I manualy insert in DB some information, it apears, so my problem starts there...
I use WAMP5 Version 1.6.4 with standart options.
Can anybody help me?

I started to think what my mistake is in the if operator... It always take me back to bagining... Why it is so?

Maybe there are other good ideas what can help me do that I want?

Yes, I have Windows XP SP2, WAMP5 Version 1.6.4 with standart options


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Jul 28, 2006 11:01 am
by ronverdonk
Where did you get that value 'upload' in $action?