PHP Files functions
simple functions
<?php $docRoot = $_SERVER['DOCUMENT_ROOT']; //readfile($docRoot."/orders/order.txt"); //do not need fopen unlink($docRoot."/orders/order.txt"); $fp = fopen($docRoot."/orders/orders.txt",rb); if($fp){ echo "open ok"; }else{ echo 'error'; } while (!feof($fp)){ echo fgetc($fp); } //fpassthru($fp); //out put string needs fopen //$len = fwrite($fp,'12345',3); rewind($fp); fseek(); fclose($fp); //file_put_contents($docRoot/orders/order.txt,'123',FILE_APPEND);
Examples
<?php // create short variable name $document_root = $_SERVER['DOCUMENT_ROOT']; ?> <!DOCTYPE html> <html> <head> <title>Bob's Auto Parts - Customer Orders</title> </head> <body> <h1>Bob's Auto Parts</h1> <h2>Customer Orders</h2> <?php @$fp = fopen("$document_root/orders/Book1.csv", 'rb'); flock($fp, LOCK_SH); // lock file for reading if (!$fp) { echo "<p><strong>No orders pending.<br /> Please try again later.</strong></p>"; exit; } while (!feof($fp)) { $order= fgets($fp); echo htmlspecialchars($order)."<br />"; } flock($fp, LOCK_UN); // release read lock echo 'Final position of the file pointer is '.(ftell($fp)); echo '<br />'; rewind($fp); echo 'After rewind, the position is '.(ftell($fp)); echo '<br />'; // while (!feof($fp)) { // // $s= fgetcsv($fp,9,','); // echo "<pre>"; // var_dump($s); // } if(is_null($s)) { echo 'null'; } fclose($fp); ?> </body> </html>
相关推荐
MXstudying 2020-09-05
WasteLand 2020-09-15
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh
mathchao 2020-09-15
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28