Re: postgresql csv import
| From: | Ashley Sheridan | Date: | Tue, 21 Sep 2021 07:02:09 +0000 |
| Subject: | Re: postgresql csv import | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-327719@lists.php.net to get a copy of this message | ||
On 21/09/2021 00:23, ourdiaspora wrote:
On Monday, September 20th, 2021 at 11:19 PM, Ashley Sheridan <ash@ashleysheridan.co.uk> wrote:You didn't need to continue after the first failure, the rest of your code won't just magically understand what you wanted it to do and fill in the gaps. $filename=$_FILES["userfile"]["tmp_name"]; That one line is not working as expected, which means that the rest of your code will fail. Now you need to ask yourself, why is that failing. What is sending the file to your PHP script in the first place? Can you show a simplified form which *only* contains the parts necessary to show the failure? -- Ashley Sheridan https://www.ashleysheridan.co.ukOn 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); }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?Did you attempt to use any kind of simple print statement debugging to see if any of your assumptions are correct?So what exactly is your code doing? Check each part: