Re: postgresql csv import
| From: | ourdiaspora | Date: | Mon, 20 Sep 2021 23:23:46 +0000 |
| Subject: | Re: postgresql csv import | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-327718@lists.php.net to get a copy of this message | ||
On Monday, September 20th, 2021 at 11:19 PM, Ashley Sheridan <ash@ashleysheridan.co.uk> wrote:
> On 20 September 2021 22:49:25 BST, ourdiaspora ourdiaspora@protonmail.com wrote:
> $targetfilepath = $uploaddir . $uploadfile;
if(isset($_POST["submit"])){
$filename=$_FILES["userfile"]["tmp_name"];
if($_FILES["file"]["size"] > 0){
$file = fopen($filename, "r");
while (($getdata = fgetcsv($file, 10000, ",")) !== FALSE){
$dbdataentry = "INSERT INTO somedata(name, id, emailaddress, groupname) VALUES
('".$getdata[0]."','".$getdata[1]."','".$getdata[2]."','"..$getdata[3]."')";
$result = pg_query($dbconnect, $dbdataentry);
}
}
fclose($file);
}
> > > So what exactly is your code doing? Check each part:
> >
> Did you attempt to use any kind of simple print statement debugging to see if any of your
> assumptions are correct?
Changed the file to:
"
...
$targetfilepath = $uploaddir . $uploadfile;
$filename=$_FILES["userfile"]["tmp_name"];
if(isset($_POST["submit"])){
$filename=$_FILES["userfile"]["tmp_name"];
if($_FILES["file"]["size"] > 0){
$file = fopen($filename, "r");
while (($getdata = fgetcsv($file, 10000, ",")) !== FALSE){
$dbdataentry = "INSERT INTO somedata(name, id, emailaddress, groupname) VALUES
('".$getdata[0]."','".$getdata[1]."','".$getdata[2]."','"..$getdata[3]."')";
$result = pg_query($dbconnect, $dbdataentry);
}
}
fclose($file);
}
print "filename is $targetfilepath";
...
"
The file path was correctly printed in the web browser.
Then substituted the last line above to:
"
...
print "filename is $filename";
...
"
The filename was _not_ printed in the web browser.
Then substituted for:
"
...
print "filename is $_FILES";
...
"
Result printed in web browser:
"
...
Notice: Array to string conversion in
...filename is Array
...
"
Then substituted for:
"
...
print "filename is $file";
...
"
Result printed in web browser:
"
...
Notice: Undefined variable: file in
...
"
Then substituted for:
"
...
print "filename is $getdata";
...
"
Result printed in web browser:
"
...
Notice: Undefined variable: getdata in
...
"
So it would seem that these variables are not being accepted?