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

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

-VladK- 25-07-06 16:18

ציטוט:

נכתב במקור על ידי drowkid
http://il.php.net/manual/he/function.file-exists.php
יש שם מלאה פונקציות... שאנשים כתבו... קרא אותם

עריכה:
אתה יודע יש לחצן בשם "ערוך" תישתמש בו...

תודה...אההההם יש לי עם זה בעיה :-/
עשיתי בדיקה והכל ותראה איזה "יופי"
http://myrand.net/new/img.php?id=1

הנה הקובץ IMG:
PHP קוד:

<?
if(isset($_GET['id'])) {
    if(
is_numeric($_GET['id'])) {
        include 
'func.php';
        include 
'db.php';
        
$id $_GET['id'];
        
$id intval($id);
        
$select mysql_query("SELECT * FROM `banners` WHERE `mid`='$id' ORDER BY rand()") or die(mysql_error());
        
$count mysql_num_rows($select);
        if(
$count != 0) {
            
$select mysql_fetch_assoc($select);
            
$url $select['url'];
            if(
url_exists($url)) {
                
$fParts explode("."$url);
                
$ext $fParts[count($fParts)-1];
                if(
$ext == "gif") {
                    
$image imagecreatefromgif ($url);
                } elseif(
$ext == "jpg") {
                    
$image imagecreatefromjpeg ($url);
                } elseif(
$ext == "jpeg") {
                    
$image imagecreatefromjpeg ($url);
                } elseif(
$ext == "png") {
                    
$image imagecreatefrompng ($url);
                }
                
$back_color imageColorAllocate($image255255255);
                
$draw_color imagecolorallocate($image255255255);
                
imagerectangle($image00imagesx($image) - 0,
                    
imagesy($image) - 0$draw_color);
                if(
$ext == "gif") {
                    
header('Content-Type: image/gif');
                    
imagegif($image);
                } elseif(
$ext == "jpg") {
                    
header('Content-Type: image/jpeg');
                    
imagejpeg($image);
                } elseif(
$ext == "jpeg") {
                    
header('Content-Type: image/jpeg');
                    
imagejpeg($image);
                } elseif(
$ext == "png") {
                    
header('Content-Type: image/png');
                    
imagepng($image);
                }
                
imageDestroy($image);
            } else {
                
nopic();
            }
        } else {
            
nopic();
        }
    } else {
        
nopic();
    }
} else {
    
nopic();
}
function 
nopic() {
    
$url 'http://myrand.net/nopic.gif';
    
$image imagecreatefromgif ($url);
    
$back_color imageColorAllocate($image255255255);
    
$draw_color imagecolorallocate($image255255255);
    
imagerectangle($image00imagesx($image) - 0,
    
imagesy($image) - 0$draw_color);
    
header('Content-Type: image/gif');
    
imagegif($image);
    
imageDestroy($image);
}
?>

הקובץ FUNC:
PHP קוד:

<?php
function url_exists($url) {
    
$a_url parse_url($url);
    if (!isset(
$a_url['port'])) $a_url['port'] = 80;
    
$errno 0;
    
$errstr '';
    
$timeout 30;
    if(isset(
$a_url['host']) && $a_url['host']!=gethostbyname($a_url['host'])) {
        
$fid fsockopen($a_url['host'], $a_url['port'], $errno$errstr$timeout);
        if (!
$fid) return false;
        
$page = isset($a_url['path'])  ?$a_url['path']:'';
        
$page .= isset($a_url['query'])?'?'.$a_url['query']:'';
        
fputs($fid'HEAD '.$page.' HTTP/1.0'."\r\n".'Host: '.$a_url['host']."\r\n\r\n");
        
$head fread($fid4096);
        
fclose($fid);
        return 
preg_match('#^HTTP/.*\s+[200|302]+\s#i'$head);
    } else {
        return 
false;
    }
}
?>


drowkid 25-07-06 16:29

סליחה...שניההההההההה........... יש לך בעיה בהרדר

-VladK- 25-07-06 16:35

ציטוט:

נכתב במקור על ידי drowkid
LOL תוסיף הרדר אני לא יודע בידיוק איזה אבל הור בטח כזה:

image/gif רק של bitmap

עריכה:
אולי:
PHP קוד:

header('Content-type: ' image_type_to_mime_type(IMAGETYPE_WBMP)); 


אבל יש לי כבר HEADER בעמוד....

drowkid 25-07-06 16:58

סמתי לב... סתקל תבודעה עוד פעם... תיבדוק תשגיעה (אם יש) בשורה 22

-VladK- 25-07-06 16:58

ציטוט:

נכתב במקור על ידי drowkid
סליחה...שניההההההההה........... יש לך בעיה בהרדר

איזה?!?

-VladK- 25-07-06 17:01

ציטוט:

נכתב במקור על ידי drowkid
סמתי לב... סתקל תבודעה עוד פעם... תיבדוק תשגיעה (אם יש) בשורה 22

בקובץ FUNC? אין כזאת שורה...

drowkid 25-07-06 17:13

בקובץ IMG.PHP

-VladK- 25-07-06 17:25

אהההם בשורה 22 יש את זה:
} elseif($ext == "png") {
ואין לזה קשר (נראה לי) לHEADER

-VladK- 26-07-06 09:27

סליחה על ההקפצה אבל זה ממש חשוב לי :(

Tomer 26-07-06 18:40

הקפצה.. נעול וקיבלת אזהרה.


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

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