Search EggHeadCafe's Job Board
EggHeadCafe Silverlight WPF ASP.NET VB.NET C# Excel SQL Server SharePoint
search
MicrosoftArticlesForumsFAQs
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml / Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

WebArticlesForumsFAQs
JavaScript
ASP
ASP.NET
WCF

DatabasesArticlesForumsFAQs
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsFAQs
Excel
Word
Powerpoint
Outlook
Publisher
Money

Non-MicrosoftArticlesForumsFAQs
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

Operating SysArticlesForumsFAQs
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsFAQs
BizTalk
Site Server
Exhange Server
IIS

Graphic DesignArticlesForumsFAQs
Macromedia Flash
Adobe PhotoShop
Expression Blend
Expression Design
Expression Web

OtherArticlesForumsFAQs
Lounge
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Product Reviews
Search Engines
Resumes

 

  View Other Open Source Posts   Ask New Question  Ask New Question With Power Editor

multiple attachments using php mysql
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
November 0 $0.00 0
October 0 $0.00 0