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

הוסטס - פורום אחסון האתרים הגדול בישראל (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 04-09-08 18:24

איך מורידים תמונה בPHP
 
נגיד אני רוצה להוריד את התמונה הזאת
http://hostscoil.net/images/styles/H.../newthread.gif
בPHP
עכשיו אני יודע רק להציג אותה
אני רוצה פשוט לעשות דף שמוריד את התמונה
איך עושים את זה?
והאם אפשר גם כאשר אני מוריד נגיד שהקובץ ירד למחשב בשם אחר
נגיד במקום newthread.gif
שירד למחשב בשם 1234.gif
איך עושים את זה
תודה רבה

Elad-A 04-09-08 18:28

http://il2.php.net/manual/en/function.header.php#83384

dabi 04-09-08 18:32

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

תודה

AlmogBaku 04-09-08 18:46

תסתכל שם, זה כתוב..

dabi 04-09-08 21:46

מוזר
רשמתי את הקוד הבא

PHP קוד:

<?php

$filename 
'http://hostscoil.net/images/styles/Hostsky/buttons//reply.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);
?>

וזה מוריד לי אכן קובץ אבל אין בו שום דבר לתצוגה
בבקשה עזרה

Tomer 05-09-08 00:44

ההפנייה לפונקציית ה header שביקשת היא כדי לתת את הקובץ המבוקש לגולש, שיוכל להוריד אותה.

אם אתה רוצה להוריד את הקובץ עצמו לשרת, תוכל להשתמש ב file_get_contents ו file_put_contents (fwrite).

dabi 05-09-08 01:11

ציטוט:

נכתב במקור על ידי Tomer (פרסם 665487)
ההפנייה לפונקציית ה header שביקשת היא כדי לתת את הקובץ המבוקש לגולש, שיוכל להוריד אותה.

אם אתה רוצה להוריד את הקובץ עצמו לשרת, תוכל להשתמש ב file_get_contents ו file_put_contents (fwrite).

נו כן אני רוצה לתת למשתמש להוריד את הקובץ למחשב
למה הקוד שרשמתי למעלה לא עבד לי בשרת שלי
תודה

בניה 05-09-08 08:01

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

Jerba 05-09-08 10:31

שלח GET לשרת עם HEADERים המתאימים בHTTP ותוריד תתמונה...

Tomer 05-09-08 12:24

תנסה לתת למשתמש קובץ שמאוחסן על השרת שלך, ולא על שרת חיצוני. לדעתי זו התקלה.

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:16.

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