• Print

Author Topic: http.Post  (Read 15825 times)

0 Members and 1 Guest are viewing this topic.

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: http.Post
« Reply #15 on: June 04, 2014, 03:58:32 pm »
I sent an example POST request using a Chrome extension (so clear statistics.csv), and everything seems to work OK.
Though, from what I see in your Lua (noticing this now):
Code: Lua
  1. port = GetConVarString( 'ip' ) .. GetConVarString( 'hostport' )
would return something like:
<ip><port>
(ex. 127.0.0.11234)
Wondering if you wanted that over:
<ip>:<port>
(ex. 127.0.0.1:1234)

Yeah, I forgot to add that in. But I looked at the page and saw that only the first line of statistics.csv would show up, instead of all lines.
Am I setting $line to the correct table? Or should I just use $handle instead?
Out of the Garry's Mod business.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: http.Post
« Reply #16 on: June 04, 2014, 07:40:16 pm »
Yeah, I forgot to add that in. But I looked at the page and saw that only the first line of statistics.csv would show up, instead of all lines.
Am I setting $line to the correct table? Or should I just use $handle instead?
Either try $handle, or use fgetcsv(); without the second parameter.
I believe the latter would work, but try both.
bw81@ulysses-forums ~ % whoami
Homepage

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: http.Post
« Reply #17 on: June 04, 2014, 11:39:21 pm »
Nope, $handle gives me an error, and fgetcsv without the kb parameter does the same thing.
Out of the Garry's Mod business.

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: http.Post
« Reply #18 on: June 05, 2014, 10:02:54 am »
If you look at the Documentation for fgetcsv(), You'll notice it says a few relevant things:
Quote from: thething
fgetcsv — Gets line from file pointer and parse for CSV fields
This pretty much states that fgetcsv only returns one line of the file- It starts from the last read part of the file, and reads until it hits a newline, the specified length, or the end of the file. This means you'll need to make a loop to iterate through each line of the file, and the easiest way to do that involves what the documentation says here:
Quote from: hipotato
fgetcsv() returns NULL if an invalid handle is supplied or FALSE on other errors, including end of file.
So, you can create a while loop that not only reads your next line, but checks for end of file as well. This can be done like so:
Code: PHP
  1. while (($line = fgetcsv($handle, 1000, ",")) !== FALSE) {  // This will continue if $line was set to a valid value
  2.     // Do what you want with $line here.
  3. }

It might look a bit confusing, but it makes sense when you realize that the assignment operator returns the assigned value, which you can then check. The following illustrates that point (PHP Interactive shell):
Code: [Select]
php > if ($hi = "test") { echo "true"; }
true
php > if ($hi = "") { echo "true"; }
php >
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: http.Post
« Reply #19 on: June 07, 2014, 08:17:09 pm »
If you look at the Documentation for fgetcsv(), You'll notice it says a few relevant things:This pretty much states that fgetcsv only returns one line of the file- It starts from the last read part of the file, and reads until it hits a newline, the specified length, or the end of the file. This means you'll need to make a loop to iterate through each line of the file, and the easiest way to do that involves what the documentation says here:So, you can create a while loop that not only reads your next line, but checks for end of file as well. This can be done like so:
Code: PHP
  1. while (($line = fgetcsv($handle, 1000, ",")) !== FALSE) {  // This will continue if $line was set to a valid value
  2.     // Do what you want with $line here.
  3. }

It might look a bit confusing, but it makes sense when you realize that the assignment operator returns the assigned value, which you can then check. The following illustrates that point (PHP Interactive shell):
Code: [Select]
php > if ($hi = "test") { echo "true"; }
true
php > if ($hi = "") { echo "true"; }
php >

Thanks Stickly! That got the entire csv to print!
Out of the Garry's Mod business.

  • Print