שליחת קובץ לדפדפן

dedtheded

New member
שליחת קובץ לדפדפן

כיצד אני יכול לשלוח קובץ לדפדפן רק אחרי תנאי מסויים? האם יש header שעושה זאת? ואם כן , האם אני יכול להפנות את ההורדה לכל מקום פיזי במחשב על השרת? בר.
 

Terminal Frost

New member
וודאי

תבדוק את התנאי שלך, ותשלח
header("location: ");​
בהתאם לתוצאות. את הLOCATION תכוון לקובץ שאתה רוצה שהלקוח יקבל.
 

dedtheded

New member
אבל...

אני רוצה להפנות לקובץ שאינו על השרת , כלומר - לא ניתן לגשת אל הקובץ סתם כך. רק דף הPHP יוכל להעביר למשתמש את הקובץ. האם יש דרך לעשות זאת? בר.
 

ShaharEvron

New member
עם PHP אפשר, אבל...

שים לב טוב למה אתה עושה, במובן האבטחתי.
<?php $fname = "file.ext" // The file you want to send, witout the path $file = "/path/to/file/" . $file_name // The path to the file if (...) { // Whatever the condition is // Open and read file $fh = fopen($file, "rb"); $c_length = (int) filesize($file); $content = fread($fh, $c_length); fclose($fh); // Send HTTP headers to browser header("Content-type: application/octet-stream; name='$fname'"); header("Content-disposition: inline; filename='$fname'"); header("Content-length: $c_length"); // Send file echo $content; } else { ... // Do whatever you want } ?>​
אם זה לא מספיק, יש דיון מעניין באתר של PHP בתיאור של הפונקציה header
 
למעלה