douqiang6448 2013-10-21 09:55
浏览 131

file_get_contents()不适用于本地服务器上的文件并通过http访问

I'm having problems with a wordpress plugin which works with file_get_contents() The plugin author said this:

"There is a problem with the way file_get_contents() is configured to work on your server. This is the core PHP function which the Wordpress function wp_remote_get() uses. This function is vital to incorporate any file that is not a part of Wordpress Media library.

The problem with file_get_contents() is that it is not working for files which are there on your local server and accessed via http."

Can anyone tell me what to do or have some spare time to help me? I am not a programmer and have no idea on how to solve this. The hosting company said that the don't offer support for software related issues, pffff!

Best Regards, Gabriel

  • 写回答

1条回答 默认 最新

  • dongma7725 2013-10-21 10:14
    关注

    Solved this by using CURL. Here's the code. It will work with remote files e.g. http://yourdomain.com/file.ext

    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, ''.$file_path_str.'');
    curl_setopt($ch, CURLOPT_HTTPGET, 1);
    curl_setopt ($ch, CURLOPT_HEADER, 0);
    curl_setopt ($ch, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    $curl_response_res = curl_exec ($ch);
    curl_close ($ch);
    

    Thanks

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100