logo

multiple attachments using php mysql (Open Source)
R P posted at Tuesday, April 14, 2009 8:34 PM

Hi, 

i wonder where i went wrong here:

if($_POST['getfile3'] != ""){
//insert attachment
$fileName = $_FILES['userfile3']['name'];
$tmpName  = $_FILES['userfile3']['tmp_name'];
$fileSize = $_FILES['userfile3']['size'];
$fileType = $_FILES['userfile3']['type'];

//echo"<br> go here<br />";
$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}
$fetch2 = ("INSERT INTO attachment2 (
                tech_id,
                FileName,
                FileMime,
                Filesize,
                FileData,
                Created)
            VALUES (
                '$tech_id',
                '$fileName',
                '$fileType',
                '$fileSize',
                '$content',
                 NOW())
        ")
or die(mysql_error());
mysql_query($fetch2) or die(mysql_error());
mysql_close();
}

if($_POST['getfile4'] != ""){
//insert attachment
$fileName = $_FILES['userfile4']['name'];
$tmpName  = $_FILES['userfile4']['tmp_name'];
$fileSize = $_FILES['userfile4']['size'];
$fileType = $_FILES['userfile4']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}
$fetch2 = ("INSERT INTO attachment2 (
                tech_id,
                FileName,
                FileMime,
                Filesize,
                FileData,
                Created)
            VALUES (
                '$tech_id',
                '$fileName',
                '$fileType',
                '$fileSize',
                '$content',
                 NOW())
        ")
or die(mysql_error());
mysql_query($fetch2) or die(mysql_error());
mysql_close();
}
if($_POST['getfile5'] != ""){
//insert attachment
$fileName = $_FILES['userfile5']['name'];
$tmpName  = $_FILES['userfile5']['tmp_name'];
$fileSize = $_FILES['userfile5']['size'];
$fileType = $_FILES['userfile5']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}
$fetch3 = ("INSERT INTO attachment2 (
                tech_id,
                FileName,
                FileMime,
                Filesize,
                FileData,
                Created)
            VALUES (
                '$tech_id',
                '$fileName',
                '$fileType',
                '$fileSize',
                '$content',
                 NOW())
        ")
or die(mysql_error());
mysql_query($fetch3) or die(mysql_error());
mysql_close();
}
if($_POST['getfile6'] != ""){
//insert attachment
$fileName = $_FILES['userfile6']['name'];
$tmpName  = $_FILES['userfile6']['tmp_name'];
$fileSize = $_FILES['userfile6']['size'];
$fileType = $_FILES['userfile6']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}
$fetch4 = ("INSERT INTO attachment2 (
                tech_id,
                FileName,
                FileMime,
                Filesize,
                FileData,
                Created)
            VALUES (
                '$tech_id',
                '$fileName',
                '$fileType',
                '$fileSize',
                '$content',
                 NOW())
        ")
or die(mysql_error());
mysql_query($fetch4) or die(mysql_error());
mysql_close();
}

as you can see all were just the same codings in different fields in a form. i was trying to upload multiple attachments here but php giving me errors or warnings:


Warning: fread(): supplied argument is not a valid stream resource in C:\xampp\htdocs\teamsite\support\tech_submit.php on line 69

Warning: fclose(): supplied argument is not a valid stream resource in C:\xampp\htdocs\teamsite\support\tech_submit.php on line 71

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\teamsite\support\tech_submit.php on line 164

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampp\htdocs\teamsite\support\tech_submit.php on line 164
Access denied for user 'ODBC'@'localhost' (using password: NO)

the first attachment had been uploaded but the others were not.

Please help.
Thanks in advance! I appreciate it.

-R
Reply    Reply Using Power Editor
  Rank Winnings Points
February 0 $0.00 0
January 0 $0.00 0

Didn't Find The Answer You Were Looking For?

EggHeadCafe has experts online right now that may know the answer to your question.  We pay them a bonus for answering as many questions as they can.  So, why not help them and yourself by becoming a member (free) and ask them your question right now?
Ask Question In Live Forum

If you have an OpenID and do not want to become a member of the EggHeadCafe forum, you can also sign on to Chat Chaos and post your question to our real time Silverlight chat application.
Ask Question In Chat Chaos










  $1000 Contest    [)ia6l0 iii - $228  |  Jonathan VH - $161  |  Huggy Bear - $135  |  F Cali - $95  |  egg egg - $94  |  more Advertise  |  Privacy  |   (c) 2010