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

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

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线