duanshang9426 2016-06-28 09:40
浏览 46

如何更改目录? 用PHP

when I worked with wamp, I had no problems, because I could have all of my files in same directory, but now I am using hosts server, so I have to change the path to the file I am working with, so PY files would work. Hello.php is in /public_html/wp-content/plugins and PY, that php is working with, is in /public_html/cgi-bin. This is hello.php code:

<?php # -*- coding: utf-8 -*-
/* Plugin Name: hello */                    
header('Content-Type: text/html; charset=cp1252');
add_shortcode( 'hello', 'execute_python_with_argv' );   
function execute_python_with_argv(){            
ob_start();
$description = array (     
0 => array("pipe", "r"),  // stdin
1 => array("pipe", "w"),  // stdout
);
$application_system = "python ";
$application_path .= plugin_dir_path( __FILE__ );
$application_name .= "hello.py";                
$separator = " ";
$application = $application_system.$application_path.$application_name.$separator;
$pipes = array();
$proc = proc_open ( $application , $description , $pipes );
if (is_resource ( $proc ))
{
echo stream_get_contents ($pipes [1] ); //Reading stdout buffer
}
echo "soup";
$output = ob_get_clean();
return $output;
}

I have tried changing $application_path .= plugin_dir_path( __FILE__ ); to $application_path = $_SERVER['DOCUMENT_ROOT']; $application_path .= "/public_html/cgi-bin/hello.py"; didn't do anything. Any help would be appreciated, thanks for reading.

  • 写回答

1条回答 默认 最新

  • douzhongjian0752 2016-06-28 09:51
    关注

    Use chdir and getcwd functions.

    getcwd — Gets the current working directory

    chdir — Change directory

    Changes PHP's current directory to directory.

    <?php
    
    // current directory
    echo getcwd() . "
    ";
    
    chdir('cvs');
    
    // current directory
    echo getcwd() . "
    ";
    
    ?>
    

    The above example will output something similar to:

    /home/didou
    /home/didou/cvs
    
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源