dongtang1997 2017-03-22 06:04
浏览 31
已采纳

尝试使用PHP shell_exec()导入CSV到MongoDB但似乎不起作用

I am trying to import a CSV to server's mongoDB by php. I already done the update file part and now I can get the CSV file that client update to the server. so now I am trying to import CSV file to mongoDB by using shell_exec() , here is my PHP code.

$importCommand = 'mongoimport -d test -c test --type csv --file yourfile.csv --headerline'; $output = shell_exec($importCommand.' 2>&1'); echo $output;

when I run this part of code in terminal by php -f it works(I know my CSV is not there so no import has been made),

$ mongoimport -d test -c test --type csv --file yourfile.csv --headerline 2017-03-22T13:46:22.668+0800 Failed: open yourfile.csv: no such file or directory 2017-03-22T13:46:22.668+0800 imported 0 documents"

as can be seen this works perfectly fine. The 'mongoimport' can be found and work fine. However when I add this to my php that use to update the file the output become

sh: mongoimport: command not found

Any idea how to solve this problem? Thanks for your time.

  • 写回答

1条回答 默认 最新

  • dongpo1203 2017-03-22 06:24
    关注

    I think I know, its due to my webserver process won't necessarily be set up with the same configuration as your own account.

    MongoDB's bin is for me, but apache user is '_www'.

    so I need to fix this privilege to get my PHP run mongoimport via safari. or input /usr/local/mongodb/bin/mongoimport to get it done

    Thanks StackOF I can answer myself by just posting here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器