首页 \ 问答 \ 从PHP中执行curl获取输出(Get output from curl executed in PHP)

从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
更新时间:2023-04-18 14:04

最满意答案

我不确定你正在使用哪个图表库,但其中大多数需要一个字符串或整数数组,并给它们一些对象。

我认为你只需要将你的数组转换成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>

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。