douyouzheng2209 2014-06-21 05:16
浏览 18
已采纳

将上传文件从PHP移动到CGI

Im trying to pass post file information to an upload.php file and have that information be sent to a CGI script. There is nothing on the net on how to go about doing this that i can find, iv spent days. I know there are a few people out there that need this, it could help us all that have legacy perl scripts.

Dataflow:
Jquery --> Upload.php --> index.cgi

My php:

<?php
if(isset($_FILES['file'])) {  

if(move_uploaded_file($_FILES['file']['tmp_name'], "../index.cgi" . $_FILES['file']['name'])){  

            echo "success";  

           exit;  
}  
}  
?>

Post call to CGI example:

foobar.com/index.cgi?act=store&data=$filename

Any suggestions would help greatly. Thank you.

  • 写回答

1条回答 默认 最新

  • dsideal2015 2014-06-21 05:31
    关注

    From my understanding, your CGI script is receiving a parameter which is the path of the uploaded script. However you are attempting to pass the uploaded script to your CGI script using a function that is only supposed to move a file from 1 place to another without executing a script. my suggestion is to do the following

    <?php
    if(isset($_FILES['file'])) {  
        $destination = "new/path/to/".$_FILES['file']['name'];
        if(move_uploaded_file($_FILES['file']['tmp_name'], $destination)){  
    
            $data = array();
            //You can add multiple post parameters here
            //$data = array('param1' => 'value1', 'param2' => 'value2');
            $url = "http://url/to/hello.cgi";
            // You can POST a file by prefixing with an @ (for <input type="file"> fields)
            $data['file'] = '@'.$destination;
    
            $handle = curl_init($url);
            curl_setopt($handle, CURLOPT_POST, true);
            curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
            $result = curl_exec($handle);
            if($result) {
               echo "success";
            }    
             exit;  
        }  
    }  
    
    ?>
    

    You can execute the cgi script via a CURL POST and pass any params you want

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度