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

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

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题