PHP 背景程式配置config檔案,及form表單上傳檔案

來源:互聯網
上載者:User

標籤:

一,配置config檔案

1擷取config.php檔案數組,

2擷取form 表單提交的值

3儲存更新config.php檔案,代碼如下:

 1         $color=$_POST[‘color‘]; 2         $backtype=$_POST[‘backtype‘]; 3          4         $settings=include(dirname(__DIR__).‘/config.php‘); 5          6         $settings[‘themescolor‘]=(int)$color; 7         $settings[‘themesbackground‘]=(int)$backtype; 8          9         //開啟輸出緩衝區10         ob_start(); 11 12         //返回數組產生的php代碼13         var_export($settings);14 15         //返回內部緩衝區的內容16         $arrStr = ob_get_contents();17 18         //刪除內部緩衝區的內容,並且關閉內部緩衝區19         ob_end_clean();20 21         $config = ‘<?php‘ . PHP_EOL22         . ‘return ‘ . $arrStr.‘;‘;23 24         //把字串寫入設定檔中。25         file_put_contents(dirname(__DIR__).‘/config.php‘, $config);

config.php 檔案如下:

<?phpreturn array (  ‘themescolor‘ => 3,  ‘themesbackground‘ => 3,);

 二 ,form上傳檔案

代碼如下:

      if ((($_FILES["path"]["type"] == "image/gif")||($_FILES["path"]["type"] == "image/jpeg")||                ($_FILES["path"]["type"] == "image/png"))&&($_FILES["path"]["size"] < 500000))        {            if ($_FILES["path"]["error"] > 0)            {                echo "Return Code: " . $_FILES["path"]["error"] ;            }            else            {                if(!file_exists($pathhd)){       //判斷儲存目錄是否存在                    mkdir($pathhd,0777,true);    //建立儲存目錄                }                                 $tool->deleteAll($pathhd);    //清空head檔案夾                        //將上傳的檔案移動到新位置。                move_uploaded_file($_FILES["path"]["tmp_name"],$pathhd.‘/‘.$_FILES["path"]["name"]);                             }        }        else        {                        echo "Invalid file";
        }

 

PHP 背景程式配置config檔案,及form表單上傳檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.