dsvtnz6350 2016-02-28 18:09
浏览 109
已采纳

在循环中的一个php内执行另一个php文件

I have a php code that has if statements(to export as pdf, to export as excel and the last one to upload excel).

The first two if's to upload pdf and excel are working fine, when I click on the button to run the the third if statement, it shows me blank page, even though the code for it is working fine when I run it separately.

My php code is below:

<?php
define('FPDF_FONTPATH','/Applications/XAMPP/xamppfiles/lib/php'); 
if (isset($_POST['pdf'])) {
     //code//
}
}
if (isset($_POST['excel'])) {
    //code//

}

if (isset($_POST['upload'])) {

exec( 'imp.php');

}
?>

The imp.php file which I am trying to run is:

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = '';

$database = 'mydatabase';
$table = 'demo';

if (!@mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");


    if(isset($_POST['submit']))
    {
         $fname = $_FILES['sel_file']['name'];
         echo 'upload file name: '.$fname.' ';
         $chk_ext = explode(".",$fname);

         if(strtolower(end($chk_ext)) == "csv")
         {

             $filename = $_FILES['sel_file']['tmp_name'];
             $handle = fopen($filename, "r");

             while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
             {
                $sql = "INSERT into demo(orders,quantity,country,dates,comment) values('$data[0]','$data[1]','$data[2]', '$data[3]','$data[4]')";
                mysql_query($sql) or die(mysql_error());
             }

             fclose($handle);
             echo "Successfully Imported";

         }
         else
         {
             echo "Invalid File";
         }   
    }

    ?>
    <h1>Import CSV file</h1>
    <form action='<?php echo $_SERVER["PHP_SELF"];?>' method='post' enctype="multipart/form-data">
        Import File : <input type='file' name='sel_file' size='20'>
        <input type='submit' name='submit' value='submit'>
    </form
  • 写回答

1条回答 默认 最新

  • dongque3797 2016-02-28 18:24
    关注

    exec function executes file on server. You won't see anything unless you explicitly get result of exec to a variable and output it.

    But as I see - you just want to include some php file into another - for this are include and require are supposed:

    include '/path/to/file.php';
    

    This will be enough.

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

报告相同问题?

悬赏问题

  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄