Re: Stuck trying to upload and grab file name

From: Date: Tue, 24 Jul 2012 09:22:51 +0000
Subject: Re: Stuck trying to upload and grab file name
References: 1 2 3 4 5  Groups: php.db 
Request: Send a blank email to php-db+get-48338@lists.php.net to get a copy of this message
Use $_FILES["file"]["tmp_name"] El martes, 24 de julio de 2012, Brad escribió: > <?php**** > > var_dump($_FILES);**** > > //db connection**** > > require 'dbConnect.php';**** > > //session file**** > > require_once('../auth.php');**** > > function uploadList(){**** > > //var_dump($_FILES['file']);**** > > if ($_FILES["file"]["type"] == "text/plain")**** > > {**** > > if ($_FILES["file"]["error"] > 0)**** > > {**** > > echo "Return Code: " . > $_FILES['file']['error'] . > "<br />";**** > > }**** > > else**** > > {**** > > dbConnect();**** > > mysql_select_db('mailList') or die(mysql_error()); > **** > > //$file=''**** > > $file = $_FILES['tmp_name'];**** > > //$presql = "CREATE TABLE IF NOT EXISTS > ($_SESSION[SESS_MEMBER_ID]_$file)";**** > > $presql = "CREATE TABLE IF NOT EXISTS > $_SESSION[SESS_MEMBER_ID]_$file";**** > > $sql = <<<EOF**** > > LOAD DATA LOCAL INFILE '{$_FILES['tmp_name']}'**** > > INTO TABLE > $_SESSION[SESS_MEMBER_ID]_$file**** > > FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY > '\\'**** > > LINES TERMINATED BY "\\r\\n"**** > > IGNORE 1 LINES**** > > EOF;**** > > mysql_query($presql);**** > > mysql_query($sql);**** > > //var_dump($sql);**** > > echo '$sql';**** > > if(mysql_error())**** > > {**** > > echo(mysql_error());**** > > }**** > > else**** > > {**** > > print('Import of campaign emails > sucessfull into mysql table.');**** > > }**** > > }**** > > }**** > > else**** > > {**** > > print('Invalid file type. Please make sure it is a text > file.');**** > > }**** > > }**** > > ** ** > > //var_dump($_FILES);**** > > uploadList();**** > > ?>**** > > ** ** > > ** ** > > array(1) { ["file"]=> array(5) { ["name"]=> string(14) > "emailsTest.txt" > ["type"]=> string(10) "text/plain" ["tmp_name"]=> > string(14) > "/tmp/phpq8pi44" ["error"]=> int(0) ["size"]=> int(61) } } > *Notice*: Undefined index: tmp_name in */home/ > nyctelecomm.com/www/mail/import.php* on line *20* > > *Notice*: Undefined index: tmp_name in */home/ > nyctelecomm.com/www/mail/import.php* on line *24* > $sqlYou have an error in your SQL syntax; check the manual that > corresponds to your MySQL server version for the right syntax to use near > ''\' LINES TERMINATED BY "\r\n" IGNORE 1 LINES' at line 3**** > > ** ** > > *From:* Roberto Carlos Garcia Luis [mailto:legnakarlos@gmail.com<javascript:_e({}, > 'cvml', 'legnakarlos@gmail.com');>] > > *Sent:* Tuesday, July 24, 2012 5:12 AM > *To:* Brad > *Cc:* php-db@lists.php.net <javascript:_e({}, 'cvml', > 'php-db@lists.php.net');> > *Subject:* Re: [PHP-DB] Stuck trying to upload and grab file name**** > > ** ** > > In the > LOAD DATA LOCAL INFILE '{$_FILES['file']['name']}'**** > > You need use The tmp_name to load The file contents.**** > > And The SQL var result as a string diferent of The SQL that you insert in > console**** > > ** ** > > > El martes, 24 de julio de 2012, Brad escribió:**** > > The tmp_file is just gibberish. I ‘truly’ do not want that as the table > name.**** > > **** > > **** > > **** > > **** > > *From:* Roberto Carlos Garcia Luis [mailto:legnakarlos@gmail.com] > *Sent:* Tuesday, July 24, 2012 4:26 AM > *To:* Brad > *Cc:* php-db@lists.php.net > *Subject:* Re: [PHP-DB] Stuck trying to upload and grab file name**** > > **** > > You need to use te tmp_name ... The plain text file is in path indicated > by The string...**** > > **** > > Regards,**** > > > El martes, 24 de julio de 2012, Brad escribió:**** > > I am making a function that uploads a txt file in csv format and the grabs > uploaded file name and the memberID from the sessions login and names the > new table memberID_filename. > > The program error on line 24 @ 'name'. > > > > I have tried '{$_FILES[file][name]}' '{$_FILES[file]['name']}' > '{$_FILES['file']['name']}' {$_FILES[file][name]} > {$_FILES['file']['name']} > $_FILES[file][name] $_FILES[file]['name'] > $_FILES['file']['name'] > '$_FILES[file][name]' '$_FILES['file']['name']' and > '$_FILES[0]['name']' > > > > ********************************code************************* > > > > <?php > > var_dump($_FILES); > > //db connection > > require 'dbConnect.php'; > > //session file > > require_once('../auth.php'); > > function uploadList(){ > > //var_dump($_FILES); > > if ($_FILES["file"]["type"] == "text/plain") > > { > > if ($_FILES["file"]["error"] > 0) > > { > > echo "Return Code: " . > $_FILES['file']['error'] . > "<br />"; > > } > > else > > { > > dbConnect(); > > mysql_select_db('mailList') or die(mysql_error()); > > //$file='' > > $file = $_FILES['file']['name']; > > //$presql = "CREATE TABLE IF NOT EXISTS > ($_SESSION[SESS_MEMBER_ID]_$file)"; > > $presql = "CREATE TABLE IF NOT EXISTS > $_SESSION[SESS_MEMBER_ID]_$file"; > > $sql = <<<EOF > > LOAD DATA LOCAL INFILE > '{$_FILES['file']['name']}' > > INTO TABLE > $_SESSION[SESS_MEMBER_ID]_$file > > FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY > '\\' > > LINES TERMINATED BY "\\r\\n" > > IGNORE 1 LINES > > EOF; > > mysql_query($presql); > > mysql_query($sql); > > var_dump($sql); > > echo '$sql'; > > if(mysql_error()) > > { > > echo(mysql_error()); > > >

« previous php.db (#48338) next »