从PHP中执行curl获取输出(Get output from curl executed in PHP)
我正在使用sonicAPI尝试上传文件。 出于某种原因,我无法在php中使用curl来做到这一点,因为他们的api需要模拟从表单发布的标志-F((HTTP))这可以让curl模拟用户按下提交的填充表单按钮)
无论如何。 我必须使用
exec("$curl https://api.sonicapi.com/file/upload?access_id=$accessId -Ffile=@./shortaudio.mp3 2>&1", $output, $exit);
上传文件。 直接输入到shell中时,引号中的命令有效。 它返回一个xml字符串。 然而,当我var_dump($ output)时,我只是在实际的shell中执行时才得到实际没有显示的'加载'信息。 我明白了
array(4) { [0]=> string(79) " % Total % Received % Xferd Average Speed Time Time Time Current" [1]=> string(77) " Dload Upload Total Spent Left Speed" [2]=> string(158) " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 17008 100 249 100 16759 393 26489 --:--:-- --:--:-- --:--:-- 26517" [3]=> string(249) "" }
我如何获得应该返回的xml字符串? 该文件确实上传成功,所以defo应该是一个XML响应。 或者,如果不是,我如何通过php curl来模拟表单发布?
I am using sonicAPI to try and upload a file. For some reason I cannot do this using curl within php because their api requires the flag -F which emulated posting from a form....((HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button)
Anyway. I have to use
exec("$curl https://api.sonicapi.com/file/upload?access_id=$accessId -Ffile=@./shortaudio.mp3 2>&1", $output, $exit);
to upload the file. The command in the quotation marks works when entered directly into a shell. It returns an xml string. However, when I var_dump($output), I just get the 'loading' information that is not actually shown in when executing it in an actual shell. I get this
array(4) { [0]=> string(79) " % Total % Received % Xferd Average Speed Time Time Time Current" [1]=> string(77) " Dload Upload Total Spent Left Speed" [2]=> string(158) " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 17008 100 249 100 16759 393 26489 --:--:-- --:--:-- --:--:-- 26517" [3]=> string(249) "" }
How do I get the xml string that should be returned? The file does get uploaded successfully, so there defo should be an xml response. Or, if not, how do I emulate form posting via php curl?
原文:https://stackoverflow.com/questions/45490432
最满意答案
我不确定你正在使用哪个图表库,但其中大多数需要一个字符串或整数数组,并给它们一些对象。
我认为你只需要将你的数组转换成php(或javescript)
php的方式:
$temp = Temps::select('temp'`) ->orderBy('date_temp','asc') ->get() ->pluck('temp'); $dateTemp = Temps::select(['temps', 'data-temp']) ->orderBy('date_temp','asc') ->get() ->pluck('data-temp'); // I am not whats the acual query you want but this is the idea
然后如果你使用laravel 5.5,只需在你的刀片上写入
<script> window.onload = function() { var ctx = document.getElementById("myChart"); var myChart = new Chart(ctx, { type: 'line', data: { labels: @json($temp), datasets: [{ label: 'Temperature', data: @json($dateTemp) , borderWidth: 1 }] } }); } </script>
I am not sure which Chart library you are using but most of them wants an array of strings or integer and you give them array of objects.
I think that you just need to convert your array in the php (or in the javescript)
php way:
$temp = Temps::select('temp'`) ->orderBy('date_temp','asc') ->get() ->pluck('temp'); $dateTemp = Temps::select(['temps', 'data-temp']) ->orderBy('date_temp','asc') ->get() ->pluck('data-temp'); // I am not whats the acual query you want but this is the idea
and then if you using laravel 5.5 just write on your blade
<script> window.onload = function() { var ctx = document.getElementById("myChart"); var myChart = new Chart(ctx, { type: 'line', data: { labels: @json($temp), datasets: [{ label: 'Temperature', data: @json($dateTemp) , borderWidth: 1 }] } }); } </script>
相关问答
更多-
在下面的答案中,我假设你熟悉Blade扩展 。 这种方法已经在Laravel 5.2和5.3上进行了测试(见下面的注释)。 在测试Ismail RBOUH的答案后 (请阅读它),解决方案似乎有两个问题: 1- $ isDisplayed变量与其他包含的小部件不在同一范围内,因此每个@include都将其脚本推送到堆栈。 因此,我将其更改为: Blade::directive('pushonce', function ($expression) { $isDisplayed = '__pushonce ...
-
我不确定你正在使用哪个图表库,但其中大多数需要一个字符串或整数数组,并给它们一些对象。 我认为你只需要将你的数组转换成php(或javescript) php的方式: $temp = Temps::select('temp'`) ->orderBy('date_temp','asc') ->get() ->pluck('temp'); $dateTemp = Temps::select(['temps', 'data-temp']) ->orderBy('date_tem ...
-
你可以直接把js / CSS放到你的公共文件夹中,如果它们不需要先编译(这是你的情况) - 这没有什么害处 但是如果你想按照建议去: 使用NPM拉库, 将js / CSS添加到要复制到公用文件夹的gulpfile.js中: elixir((mix)=> { mix.sass('app.scss') .webpack('app.js') .mix.copy('node_modules/foo/bar.css', 'public/css/bar.css'); }); https://laravel.com/d ...
-
Laravel:如何通过JSON将Blade模板传递给客户端?(Laravel: How to I pass a Blade template to the client side via JSON?)[2022-02-03]
我认为你要找的是View :: render(); http://laravel.com/api/source-class-Laravel.View.html#311 据我所知,View :: make返回一个完整的响应对象,这不是你想要的。 I think what you are looking for is View::render(); http://laravel.com/api/source-class-Laravel.View.html#311 As far as I know, View:: ... -
也许你应该分享它出现的错误是什么? 即时通讯使用欧芹与laravel 4没有任何问题,这是我的示例代码 {{ Form::text('name',Input::old('name'),array('id'=>'name','data-required'=>'true','data-required-message'=>'Name Required','placeholder'=>'Please enter name')) }} maybe you should share what's the error ...
-
Laravel Blade不包含模板中存在的css和.js(Laravel Blade does not include css and .js present in template)[2022-12-23]
我发现了错误的位置。 我在默认模板中更改了.js和css文件的路径,并正确呈现了视图: 虽然没有正确的答案,因为这个模板提供了几个视图 - 刀片完美地工作,现在对我来说没问题。 I found out where the error is. I changed the path to .js and css files in default template and the v ... -
{{ Escaped variable }} {!! Unescaped variable !!} 从文档引用: 默认情况下,Blade {{ }}语句通过PHP的htmlentities功能自动发送,以防止XSS攻击。 如果您不希望数据被转义,则可以使用以下语法: Hello, {!! $name !!} {{ Escaped variable }} {!! Unescaped variable !!} Quote from the documentation: By default, Blade ...
-
如果你有模板内联,那么你可以输出你想要的任何内容(来自你的something.blade.php文件):
{!! $some_php_variable_sent_to_the_view !!} @{{ $data.someVueDataProperty | json }} 您可以使用刀片@include('path-to.super-duper-component')从 ... -
Laravel 5与Charts4php(Laravel 5 with Charts4php)[2023-07-19]
chartphp的命名空间不正确。 尝试new \chartphp(); The namespace of chartphp isn't correct. Try new \chartphp(); -
Laravel vue js integration - 刀片文件中没有值(Laravel vue js integration - No values in blade file)[2022-03-20]
编辑 的package.json { "private": true, "scripts": { "prod": "gulp --production", "dev": "gulp watch", "slate": "rimraf node_modules && npm install", "clean": "rimraf public/css/app.css public/css/app.css.map public/js/app.js && npm run dev ...