// 文件操作的類
<?php // Copyright 2005, Lee Babin (lee@thecodeshoppe.com) // This code may be used and redistributed without charge // under the terms of the GNU General Public // License version 2.0 or later -- www.gnu.org // Subject to the retention of this copyright // and GPL Notice in all copies or derived works class cfile { //The path to the file we wish to work with. protected $thepath; //Error messages in the form of constants for ease of use. const FOUNDERROR = "Sorry, the file in question does not exist."; const PERMERROR = "Sorry, you do not have the proper permissions on this file"; const OPENERROR = "Sorry, the file in question could not be opened."; const CLOSEERROR = "Sorry, the file could not be closed."; //The constructor function. public function __construct (){ $num_args = func_num_args(); if($num_args > 0){ $args = func_get_args(); $this->thepath = $args[0]; } } //A function to open the file. private function openfile ($readorwrite){ //First, ensure the file exists. try { if (file_exists ($this->thepath)){ //Now, we need to see if we are reading or writing or both. $proceed = false; if ($readorwrite == "r"){ if (is_readable($this->thepath)){ $proceed = true; } } elseif ($readorwrite == "w"){ if (is_writable($this->thepath)){ $proceed = true; } } else { if (is_readable($this->thepath) && is_writable($this->thepath)){ $proceed = true; } } try { if ($proceed){ //We can now attempt to open the file. try { if ($filepointer = fopen ($this->thepath, $readorwrite)){ return $filepointer; } else { throw new exception (self::OPENERROR); return false; } } catch (exception $e) { echo $e->getmessage(); } } else { throw new exception (self::PERMERROR); } } catch (exception $e) { echo $e->getmessage(); } } else { throw new exception (self::FOUNDERROR); } } catch (exception $e) { echo $e->getmessage(); } } //A function to close a file. function closefile () { try { if (!fclose ($this->thepath)){ throw new exception (self::CLOSEERROR); } } catch (exception $e) { echo $e->getmessage(); } } //A function to read a file, then return the results of the read in a string. public function read () { //First, attempt to open the file. $filepointer = $this->openfile ("r"); //Now, return a string with the read data. if ($filepointer != false){ //Then we can read the file. return fgets ($filepointer); } //Lastly, close the file. $this->closefile (); } //A function to write to a file. public function write ($towrite) { //First, attempt to open the file. $filepointer = $this->openfile ("w"); //Now, return a string with the read data. if ($filepointer != false){ //Then we can read the file. return fwrite ($filepointer, $towrite); } //Lastly, close the file. $this->closefile (); } //A function to append to a file. public function append ($toappend) { //First, attempt to open the file. $filepointer = $this->openfile ("a"); //Now, return a string with the read data. if ($filepointer != false){ //Then we can read the file. return fwrite ($filepointer, $toappend); } //Lastly, close the file. $this->closefile (); } //A function to set the path to a new file. public function setpath ($newpath) { $this->thepath = $newpath; } } ?> <?php $myfile = new cfile ("test.txt"); //Now, let's try reading it. echo $myfile->read(); //Then let's try writing to the file. $myfile->write ("Hello World!"); //Then, let's try appending. $myfile->append ("Hello Again!"); ?>
// 文件下載
<?php $filename = 'file1.txt'; $file = fopen($filename, 'r'); Header("Expires: 0"); Header("Pragma: public"); Header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); Header("Cache-Control: public"); Header("Content-Length: ". filesize($filename)); Header("Content-Type: application/octet-stream"); Header("Content-Disposition: attachment; filename=".$filename); readfile($filename); ?>
在這裏分享一下通過拖取 DataCube 代碼審計後發現的一些漏洞,包括前臺的文件上傳,信息泄露出賬號密碼,後臺的文件上傳。當然還有部分 SQL 注入漏洞,因爲 DataCube 採用的是 SQLite 的數據庫,所以SQL 注入相對來說顯
PhpStorm是一個輕量級且便捷的PHP IDE,其旨在提高用戶效率,可深刻理解用戶的編碼,提供智能代碼補全,快速導航以及即時錯誤檢查。可隨時幫助用戶對其編碼進行調整,運行單元測試或者提供可視化debug功能。 立即獲取PhpStorm
<?php echo 333; // 檢查 pcntl 擴展是否安裝 if (!function_exists('pcntl_fork')) { die('PCNTL functions not available on t
您可以在這裏檢查和比較這兩種排序規則提供的排序順序: https://collation-charts.org/mysql60/mysql604.utf8_unicode_ci.european.html https://collation
前言 隨着互聯網的發展,信息獲取已經成爲了人們日常生活和工作中的重要一環。而在信息獲取的過程中,網絡爬蟲作爲一種自動化的數據採集工具,爲我們提供了極大的便利。本文將介紹如何利用PHP編寫一個簡單而高效的網絡爬蟲,實現快速爬取百度搜索的實
導語 | 近期 TIOBE 最新指數顯示,PHP 的流行度降至了歷史最低,排在第 17 名,同時,在年度 Stack Overflow 開發者調查報告中,PHP 在開發者中的受歡迎程度已經從之前的約 30% 萎縮至現在的 18%。“P
活動簡介 “飛天技術沙龍——Serverless 技術實踐營”是一場以 Serverless 爲主題的技術活動,通過一個下午的時間增進對 Serverless 技術的理解,快速上手,活動受衆以關注 Serverless 技術的開發者、企業決
本文分享自華爲雲社區《MySQL全文索引源碼剖析之Insert語句執行過程》 ,作者:GaussDB 數據庫。 1. 背景介紹 全文索引是信息檢索領域的一種常用的技術手段,用於全文搜索問題,即根據單詞,搜索包含該單詞的文檔,比如在瀏覽器
0x01 獲取webshell 在各種信息蒐集中,發現某個ip的端口掛着一個比較老的服務。 首先看到了員工工號和手機號的雙重驗證,也不知道賬號是什麼結構組成的,基本上放棄字典爆破這一條路。於是乎打開之前用燈塔的掃描結果,看看文件泄露是否
1、下載: https://www.docker.com/products/docker-desktop/ 如果電腦分多個盤,建議下載到可用存儲較大的盤,安裝的時候默認安裝到 C 盤,安裝完成後雙擊啓動 如果出現【Docker
大晚上不睡覺、枸杞泡起來@我 一個月之前、自從入了樹莓派4b 8g板之後、就無法自拔,上班除了開發業務代碼和搭建內部UI組件庫之外,就是不亦樂乎的學習docker、mysql、mongodb、php、python、frp等,採購了阿里雲E
0x01 命令執行 直接payload: 127.0.0.1 &whoami,發現可以成功執行whoami命令 然後ls ../ ,發現有個key.php文件 嘗試用cat命令查看發現不行被攔截了。(其實題目過濾了常用的查看文件的命
從可視化編排到支持 YAML 編排 雲效流水線 Flow 是開箱即用的企業級持續集成和持續交付工具,支持豐富的代碼源、構建、自動化測試工具、多種部署類型和部署方式,與阿里雲深度集成,還提供多種企業級特性,助力企業高效完成從開發到上線 CIC
一、文件屬性 下文中,“文件”一詞默認代指廣義的數據類型,跟“目錄”等詞對比使用時,則專指普通文件(File)這一特定數據類型。 Linux系統中,我們可以使用命令“ls -al”來查看當前目錄
要將Git中的一個文件恢復到之前的版本,你可以使用git checkout命令結合特定的提交哈希值(commit hash)或引用(如HEAD~1)來檢出該文件的特定版本。 以下是如何操作的步驟: 查看文件的歷史: 首先,你可以使用gi