[PHP] - สอบถาม Automatic refresh page
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา [PHP] - สอบถาม Automatic refresh page
[PHP] - สอบถาม Automatic refresh page
ปัญหาคือในโฟลเดอร์ มีภาพ 001.jpg และ echo 001.jpg แล้วเพิ่มภาพ 002.jpg
หน้า index.php จะให้แสดงภาพ 002.jpg ได้ยังไงครับ
ขอบคุณครับ
ผมก็ไปค้นหาเจอข้อมูลที่หน้าจะคล้ายสุด แต่นำไปเทสแล้ว ไม่สามารถ echo ภาพ 002.jpg ได้
https://stackoverflow.com/questions/42928102/php-automatically-refresh-page-if-the-content-of-a-specific-file-has-changed
-The content of "index.php":
-The content of "check_file_stat.php":
หน้า index.php จะให้แสดงภาพ 002.jpg ได้ยังไงครับ
ขอบคุณครับ
ผมก็ไปค้นหาเจอข้อมูลที่หน้าจะคล้ายสุด แต่นำไปเทสแล้ว ไม่สามารถ echo ภาพ 002.jpg ได้
https://stackoverflow.com/questions/42928102/php-automatically-refresh-page-if-the-content-of-a-specific-file-has-changed
-The content of "index.php":
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | <script language= "javascript" > //var myVar=setInterval(function(){chekUpdate()},5*60*1000); // at 5 minutes intervals var myVar=setInterval( function (){chekUpdate()},1000); var stat_old = "" ; function chekUpdate() { $( "#status_fisier" ).load( "check_file_stat.php" , function (){ var stat_new = $( "#status_fisier" ).html(); if ((stat_old != "" ) && (stat_old != stat_new)){ refreshSlideShow(); } stat_old = stat_new; }); } function refreshSlideShow() { // you can refresh your slideshow here. location.reload(); } </script> <body> <style> #status_fisier, #display_ticker { position: absolute; left: 0; right: 0; } #status_fisier { top: 0; height: 10%; background-color: pink; /* overflow:scroll; */ } #display_ticker { bottom: 0; height: 90%; background-color: #ddd; } </style> <div id= "status_fisier" > </div> <div id= "display_ticker" > <?php include ( "message.php" ); ?> </div> </body> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <?php $locatie_fisier_de_verificat = 'test_fisier.txt' ; /* The stat() function returns information about a file. This function returns an array with the following elements: [0] or [dev] - Device number [1] or [ino] - Inode number [2] or [mode] - Inode protection mode [3] or [nlink] - Number of links [4] or [uid] - User ID of owner [5] or [gid] - Group ID of owner [6] or [rdev] - Inode device type [7] or [size] - Size in bytes [8] or [atime] - Last access (as Unix timestamp) [9] or [mtime] - Last modified (as Unix timestamp) [10] or [ctime] - Last inode change (as Unix timestamp) [11] or [blksize] - Blocksize of filesystem IO (if supported) [12] or [blocks] - Number of blocks allocated */ $stat = stat( $locatie_fisier_de_verificat ); echo '<p>Verificare stare fisier: "' . $locatie_fisier_de_verificat . '"</p>' ; echo '<p>Timpul ultimei modificari (UNIX Timestamp): ' . $stat [ 'mtime' ] . "</p>" ; /* time of last modification (Unix timestamp) */ echo '<p>Dimensiune in bytes: ' . $stat [ 'size' ] . "</p>" ; /* size in bytes */ ?> |

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ความคิดเห็นที่
1
ไม่แน่ใจว่าทำแบบไหน แต่ถ้าใช้ location.reload() ตามตัวอย่างจะเป็นการโหลดหน้าใหม่
ข้อมูลกับตัวแปรจะถูกล้างค่าใหม่ สมมติ ถ้าต้องการแสดงรูปภาพล่าสุดที่เพิ่มเข้าไป แทนรูปเก่า
ลองใช้วิธี ใช้ชื่อเดิม อ่านข้อมูลไฟล์ใหม่แล้วเทียบค่าข้อมูลที่ต่างกัน จากนั้นตอนดึงรูปมาแสดง
ก็แสดงรูปชื่อเดิม แต่ป้องกันการแคชโดยต่อท้ายชื่อด้วย ตัวแปรเข้าไป เช่น 001.jpg?v=<?=time()?>
บทความแนะนำที่เกี่ยวข้อง | |
---|---|
ทบทวนพื้นฐาน ajax ใน jquery การส่งค่าและแสดงข้อมูลเบื้องต้น | อ่าน 31,162 |

ความคิดเห็นที่
2
1 2 3 4 5 6 7 8 9 10 | ถ้า URL เป็น localhost/test.php?year=2565& date =31 ผมจะให้ AJAX load GET จาก URL ได้ยังไงครับ $year = $_GET [ 'year' ]; $date = $_GET [ 'date' ]; { $( "#stat" ).load( "test-check.php?year=$year&date=$date" , function (){ }); } |

ความคิดเห็นที่
3
ถ้าโค้ด javascript ใช้ร่วมกับไฟล์ php ในไฟล์เดียวกัน ก็แทนตัวแปร php เข้าไปได้เลย
1 2 | $( "#stat" ).load( "test-check.php?year=<?=$year?>&date=<?=$date?>" , function (){ }); |
แต่ถ้าจะส่งค่าไปใน javascript ผ่านตัวแปรของ javascript ก็ให้สร้างตัวแปร แล้วค่าเรียกใช้งานค่า
1 2 3 4 5 | var _year = <?= $_GET [ 'year' ]?>; var _date = <?= $_GET [ 'date' ]?>; $( "#stat" ).load( "test-check.php?year=" + _year + "&date=" + _date + "" , function (){ }); |

ขอบคุณทุกการสนับสนุน
![]()