הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   איך מורידים תמונה בPHP (https://hosts.co.il/forums/showthread.php?t=67082)

dabi 05-09-08 13:43

הנה הקוד
PHP קוד:

<?php
ob_start
();

$filename='1.gif';

// fix for IE catching or PHP bug issue
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// browser must download file from server instead of cache

// force download dialog
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");

// use the Content-Disposition header to supply a recommended filename and
// force the browser to display the save dialog.
header("Content-Disposition: attachment; filename=".basename($filename).";");

/*
The Content-transfer-encoding header should be binary, since the file will be read
directly from the disk and the raw bytes passed to the downloading computer.
The Content-length header is useful to set for downloads. The browser will be able to
show a progress meter as a file downloads. The content-lenght can be determines by
filesize function returns the size of a file.
*/
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));

@
readfile($filename);
exit(
0);

?>

אני מנסה להוריד קובץ שגם בשרת שלי וגם בתיקיה שלי
מה שקורה שזה מוריד לי את הקובץ 1.gif
אבל כשאני פותח אותו אני לא רואה תמונה
עזרה בבקשה

dabi 05-09-08 15:04

אני רואה שהפונקציה readfile מבוטלת בשרת שלי
אז איך אני מוריד קובץ בלי הפונקציה readfile
תודה

בניה 05-09-08 15:19

אתה יכול להשתמש ב file_get_contents ולהדפיס את מה שהיא מחזירה לך.
או עם fopen ו fread

dabi 05-09-08 15:20

אני לא רוצה להדפיס אני רוצה להוריד בבקשה

AlmogBaku 05-09-08 16:37

זה יוריד את זה(בגלל ההאדרים ששמת למעלה).

בעקרון, אני ממליץ שתנסה להפעיל readfile...

dabi 06-09-08 20:51

ניסיתי להשתמש בפנקציה
file_get_contents
PHP קוד:

<?php
ob_start
();

$filename='1.gif';

// fix for IE catching or PHP bug issue
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// browser must download file from server instead of cache

// force download dialog
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");

// use the Content-Disposition header to supply a recommended filename and
// force the browser to display the save dialog.
header("Content-Disposition: attachment; filename=".basename($filename).";");

/*
The Content-transfer-encoding header should be binary, since the file will be read
directly from the disk and the raw bytes passed to the downloading computer.
The Content-length header is useful to set for downloads. The browser will be able to
show a progress meter as a file downloads. The content-lenght can be determines by
filesize function returns the size of a file.
*/
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));

@
file_get_contents($filename);  
exit(
0);

?>

שימו לב בשורה לפני האחרונה רשמתי
PHP קוד:

@file_get_contents($filename); 

במקום
PHP קוד:

@readfile($filename); 

וזה עדיין הוריד לי את הקובץ אבל קובץ ששוקל 0 קילו בייט ולא מכיל תמונה אלא סתם קובץ בשם 1.gif

ASTeam 06-09-08 21:33

PHP קוד:

$filename='1.gif'

שורה רביעית.
הקובץ שהגדרת לו הוא הקובץ 1.gif שנמצא בתיקייה בה הקוד שלך נמצא.
כל עוד לא תשנה את זה - זה הקובץ שיורד..(ואם לא קיים יורד ב0בייט)

dabi 06-09-08 21:36

ציטוט:

נכתב במקור על ידי ASTeam (פרסם 665944)
PHP קוד:

$filename='1.gif'

שורה רביעית.
הקובץ שהגדרת לו הוא הקובץ 1.gif שנמצא בתיקייה בה הקוד שלך נמצא.
כל עוד לא תשנה את זה - זה הקובץ שיורד..(ואם לא קיים יורד ב0בייט)

נכון בתיקיה שהקוד נמצא קיים 1.gif ואותו אני מנסה להוריד

בניה 06-09-08 21:58

קודם כל,תעיף את ה@ אם יש שגיאה אתה פשוט לא רואה אותה.
דבר שני,readfile גם קורא את התוכן של הקובץ וגם ישר טוען אותו לפלט שנשלח לדפדפן.
file_get_contents רק קורא את תוכן של הקובץ, אז אתה צריך להדפיס את מה שהפונקציה הזו מחזירה לך.


כל הזמנים הם GMT +2. הזמן כעת הוא 10:49.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ