Jump to content
coolbyte

Cum gestionez o eroare in php

Recommended Posts

Buna ziua.

Am urmatorul script:

<php> $inlocuit = array("http://", "ftp://");

$link1 = str_replace($inlocuit, "", $linkdown);

$host = substr($link1, 0, strpos($link1, "/"));

$path = strstr($link1, '/');

$port = 80;

$content_length = 0;

$fp = fsockopen($host, $port);

fputs($fp, "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n");

while (% aici am pus @%"\r\n\r\n" != ($line = fgets($fp, 1024))) {

if (preg_match("/content-length: (\d+)/i", $line, $match)) {

$content_length = $match[1];

break;

}

}

fclose($fp);

$size = $content_length;

$sizeKB=$size/1024;

if ($sizeKB >1024){

$sizeMB=$sizeKB/1024;

if ($sizeMB>1024){

$sizemb=$sizeMB/1024;

}

else{

$sizeMB = round($sizeMB,2);

echo "$sizeMB MB";

}

}

else{

$sizeKB = round($sizeKB,2);

echo "$sizeKB KB";

}

<php>

In momentul in care nu mai e valid link-ul aceasta structura se opreste si afiseaza o eroare. As dori sa sara peste acea eroare si scriptul sa se deruleze in continuare si sa aviseze de exemplu link inexistent. Am incercat cu @ dar cum nu stapanesc prea bine nu am reusit.

Multumesc

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...