I have some file_get_contents() in my code like this:
$thearray = file_get_contents('../folder/subfolder/sorting.php?arr='.json_encode($recordsarr));
where $recordsarr is a multiarray. i got an error like:
file_get_contents(../folder/subfolder/sorting.php?arr=[["463","0","68","68","0,1","68","68","0","7.50"],["463","0","61","68","2","68","68","0","8.00"],["463","0","68","68","0,1","68","68","0","8.50"],["463","0","68","68","","68,"68","0","9.00"],["463","0","68","68","","68","68","0","10.00"],["463","0","68","68","","68","01:15:00","0","6.00"]]):
failed to open stream: File name too long
At the same time, if i will open from browser this url (https://example.com/folder/subfolder/sorting.php?arr=[["463","0","68","68","0,1","68","68","0","7.50"],["463","0","61","68","2","68","68","0","8.00"],["463","0","68","68","0,1","68","68","0","8.50"],["463","0","68","68","","68,"68","0","9.00"],["463","0","68","68","","68","68","0","10.00"],["463","0","68","68","","68","01:15:00","0","6.00"]]) works fine and it shows me some content. I have read about 255 characters limitation for the file_get_contents() but is there any workaround with this situation? I can't make these arrays smaller in size. I am thinking also about CURL, but i cannot find a working example of using CURL inside existing site (and even if it is possible, it will make some outgoing traffic and increase script running time and make more load), not outside. Maybe there is a function in php, that is the same as file_get_contents(), but that allows to use longer url's?
It looks to me like you're hoping to run the php program in ../folder/subfolder/sorting.php while passing it your JSON as the arr parameter. You're hoping to get the output of that program.
But you're passing file_get_contents() a file name, not a URL. It will work if you pass it a URL. It will make an HTTP or HTTPS request to the server in question and return the results. But only if it can tell you're using a URL. Give a URL, something like https://example.com/folder/subfolder/sorting.php?arr=whatever and it may work.
Or, as you mentioned, use CURL.
Or, as #RiggsFolly suggested, refactor that sorting.php code to work as a function, and just call it.
Your filename-length failure comes from your operating system when get_file_contents() asks it to open that long file name you passed. If it were obviously a URL, get_file_contents() would not have tried to get your OS to open it as a file.
The length of your url is ok ~ 344 characters. Then you can send your query like that:
$url = http_build_query(['arr' => '[["463","0","68","68","0,1","68","68","0","7.50"],["463","0","61","68","2","68","68","0","8.00"],["463","0","68","68","0,1","68","68","0","8.50"],["463","0","68","68","","68,"68","0","9.00"],["463","0","68","68","","68","68","0","10.00"],["463","0","68","68","","68","01:15:00","0","6.00"]]',]);
$opts = ['http' =>
[
'method' => 'GET',
'content' => $url,
]];
$context = stream_context_create($opts);
$res = file_get_contents('http://example.com/send.php', false, $context);
Push the full URL and it will work:
$thearray = file_get_contents('https://example.com/folder/subfolder/sorting.php?arr='.json_encode($recordsarr));
The traffic will be very low
ran into a weird one here, maybe some of the more seniory of guys can help me come to a conclusion on what exactlies going on (already have a work around, but would like to know how to fix this as it seems it can affect other things)
So I have a line of code that will detect a CLI string (based on type[0]) and then proceed to convert and load CLI parameters into GET params.
parse_str(implode("&", array_slice($payload['args'], 1)), $_GET);
That works fine, you can test it with creating a file and issueing it something like
php - f test.php -- foo=bar bar=baz
With the contents of the file using the above line and just a print_r($_GET);
Well it get weird when you try to use this as a filter_input I've noticed but cannot figure out why
$filter = filter_input_array(INPUT_GET, [
'email' => FILTER_VALIDATE_EMAIL,
]);
print_r($filter); //empty
It also looks like trying to tack on anything to a GET request is forgone by filter_input_array in general, instance
http://localhost?request=foo
$_GET['email'] = 'Someguy#somplace.com';
//print_r($_GET); // check
print_r(filter_input_array(INPUT_GET, [
'email' => FILTER_VALIDATE_EMAIL,
'request' => FILTER_SANITIZE_ENCODED,
])):
What DOES work though for unknown reasons is
$filter = filter_var_array($_GET, [
'email' => FILTER_VALIDATE_EMAIL,
]);
Makes little to no sense to me =(
I would LIKE to believe that our GET somehow has not registered into the global scope, but I'm lacking on figuring out why...
I am running PHP 5.5.8 for Saucy, input welcome
The functions filter_input_array() and filter_input() work on the actual input, not on the corresponding global variables.
From a note in the documentation for filter_input:
Note that this function doesn't (or at least doesn't seem to) actually filter based on the current values of $_GET etc. Instead, it seems to filter based off the original values.
source
I've got a script that uploads files perfectly fine into buckets. However, one particular bucket has been given a cname so that it can be accessed directly, apparently it has been assigned this using CloudFront.
I'm no expert in this field, but basically, instead of accessing the bucket via:
http://mybucket.mysite.com.s3.amazonaws.com/thing.txt, it allows you to access it via:
http://mybucket.mysite.com/thing.txt
It performs the put fine by the looks of it, when I do a response on the callback, it says it's all done but the last element in the array swaps the bucket and the endpoint around, so it looks like this: https://s3.amazonaws.com/mybucket.mysite.com/thing.txt
However, when I use any other bucket it uploads correctly and returns the correct ObjectURL.
Having had a search around google and this site, I can't seem to find a solution so any help would be magic.
I'm using an older version of the AWS PHP 2 sdk, currently using 2.2.1.
Edit: even stranger still, when I pass the bucket through the isValidBucketName method, it returns true.
Just in case anyone else ever encounters this issue, the problem was that when executing the put, the SDK automatically assumes that you are trying to connect to a bucket in the US region. So I needed to specify what region the bucket is in, in my case EU_WEST_1, so when you set up your config array, be sure to provide this value, eg.
$config = array(
'key' => 'your-key'
, 'secret' => 'your-secret'
, 'region' => Region::EU_WEST_1
);
Being sure to include the Aws\Common\Enum\Region in the class.
At first apologies in advance if there is some problem in my ques, i am new to heroku ,my basic problem is i have some messed up code, where i want to test if i am able to fetch facebook variables in my own code and use them..
in my .php file i want to put name for person using my facebook app to displayname array variable of array and url of array should get the application users picture..i took the idea to assign these value via the index.php file provided by facebook itself.
My .php file code is :-
$basic = $facebook->api('/me');
$options = array(
'displayName' => he(idx($basic, 'name')),
'image' => array(
'url' => 'https://graph.facebook.com/'.he($id).'/picture?type=square',
'height => '48',
'width => '48'
)
);
but there is something wrong going here which i cant figure out.
i tried to debug it via javascript or other techniques but now able to connect the .php file to some .js file by any means to transfer variable values present in .php file and print them on my browser,i use to edit code at my own system and push it via git and since the code is executed at heroku i cant figure out what errors are creping in..i am using free account as per now so is there any way i can see my code in execution at heroku.. or any help to debug my code efficiently..
Edit1: alternatively is there any way i can pass these variable from my .PHP file to a separate .JS file and print variables in message box or something..any example code given will help a lot..there are many questions asked in this regard to transfer variables from separate .PHP file to separate .JS file..but i found no direct answer for it, all suggest workarounds but no direct way... questions i visited for it are ..
What's the best way to pass a PHP variable to Javascript?
Grab/input php variable in javascript?
and some more but dint find the perfect answer.
Edit2: if my ques needs more info plz let me know,and if second option is the choice left to debug my code ..then can someone give me an example with transferring variable/array present in testfile.php file say present at appfolder/php/lib/testfile.php and output it on browser in HTML format using testjs.js file say present at appfolder/lib/js/testjs.js
A common exchange format between PHP (or other language) and JavaScript is JSON. You can encode an array (or an php object) to json using json_encode, in PHP. Like this :
$options_json = json_encode($options);
So, you can write this javascript variable in your html results, like this :
echo '<script>var options = ', json_encode($options), ';</script>';
Your picture will then be accessible using javascript :
console.log(options);
console.log(options.url);