Get Remote file size without downloading file

by 0

Is there a way to get the size of a remote file http://my_url/my_file.txt without downloading the file?

Solution:

Found something about this :
Here's the best way (that I've found) to get the size of a remote file. Note that HEAD requests don't get the actual body of the request, they just retrieve the headers. So making a HEAD request to a resource that is 100MB will take the same amount of time as a HEAD request to a resource that is 1KB.
<?php/** * Returns the size of a file without downloading it, or -1 if the file * size could not be determined. * * @param $url - The location of the remote file to download. Cannot * be null or empty. * * @return The size of the file referenced by $url, or -1 if the size * could not be determined. */function curl_get_file_size( $url ) {  // Assume failure.  $result = -1;  $curl = curl_init( $url );  // Issue a HEAD request and follow any redirects.  curl_setopt( $curl, CURLOPT_NOBODY, true );  curl_setopt( $curl, CURLOPT_HEADER, true );  curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );  curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );  curl_setopt( $curl, CURLOPT_USERAGENT, get_user_agent_string() );  $data = curl_exec( $curl );  curl_close( $curl );  if( $data ) {    $content_length = "unknown";    $status = "unknown";    if( preg_match( "/^HTTP\/1\.[01] (\d\d\d)/", $data, $matches ) ) {      $status = (int)$matches[1];    }    if( preg_match( "/Content-Length: (\d+)/", $data, $matches ) ) {      $content_length = (int)$matches[1];    }    // http://en.wikipedia.org/wiki/List_of_HTTP_status_c...     if( $status == 200 || ($status > 300 && $status <= 308) ) {      $result = $content_length;    }  }  return $result;}?>
Usage:
$file_size = curl_get_file_size( "http://abc.com/questions/2602612/php-remote-file-size-without-downloading-file" );


Source: 
PHP: Remote file size without downloading file

Prevent multiple inserts when submitting a form in PHP

by in 0

Sometimes the user may press Enter twice, and the post is inserted twice.

Is there a solution to prevent this other than check if there is already a post with the same title and content?

Solutions:
1- Use JavaScript to stop it from sending

2 - disable the submit button once the user has submitted the form, using JavaScript. That is what, for example
3 - Include a unique token on each POST worked for me. However, my form still submits when a user refreshes the page (F5). I managed to solve this by adding a reset:
            // reset session token
            $_SESSION['token'] = md5( $_POST['token'] . time() );
my final scripts goes like:
if (isset($_SESSION['token'])) {
    if (isset($_POST['token'])) {
        if ($_POST['token'] != $_SESSION['token']) {
            echo '<h3>Oops! You already submitted this request.</h3>';
        } else {
            // process form
            // reset session token
            $_SESSION['token'] = md5( $_POST['token'] . time() );
        }
    } else {
        echo 'post token not set';
        $_SESSION['token'] = md5( $somevariable . time() );
    }
}
oh! don't forget to add session_start(); before <!DOCTYPE>
I am a PHP newbie so please correct me if you find irregularities.


Source:
How to prevent multiple inserts when submitting a form in PHP?



Remove URL from string PHP

by in 0

f I have a string that contains a url (for examples sake, we'll call it $url) such as;

$url = "Here is a funny site http://www.tunyurl.com/34934";
How do i remove the URL from the string? Difficulty is, urls might also show up without the http://, such as ;
$url = "Here is another funny site www.tinyurl.com/55555";

There is no HTML present. How would i start a search if http or www exists, then remove the text/numbers/symbols until the first space?


##########

function containsTLD($string) {
  preg_match(
    "/(AC($|\/)|\.AD($|\/)|\.AE($|\/)|\.AERO($|\/)|\.AF($|\/)|\.AG($|\/)|\.AI($|\/)|\.AL($|\/)|\.AM($|\/)|\.AN($|\/)|\.AO($|\/)|\.AQ($|\/)|\.AR($|\/)|\.ARPA($|\/)|\.AS($|\/)|\.ASIA($|\/)|\.AT($|\/)|\.AU($|\/)|\.AW($|\/)|\.AX($|\/)|\.AZ($|\/)|\.BA($|\/)|\.BB($|\/)|\.BD($|\/)|\.BE($|\/)|\.BF($|\/)|\.BG($|\/)|\.BH($|\/)|\.BI($|\/)|\.BIZ($|\/)|\.BJ($|\/)|\.BM($|\/)|\.BN($|\/)|\.BO($|\/)|\.BR($|\/)|\.BS($|\/)|\.BT($|\/)|\.BV($|\/)|\.BW($|\/)|\.BY($|\/)|\.BZ($|\/)|\.CA($|\/)|\.CAT($|\/)|\.CC($|\/)|\.CD($|\/)|\.CF($|\/)|\.CG($|\/)|\.CH($|\/)|\.CI($|\/)|\.CK($|\/)|\.CL($|\/)|\.CM($|\/)|\.CN($|\/)|\.CO($|\/)|\.COM($|\/)|\.COOP($|\/)|\.CR($|\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.VI($|\/)|\.VN($|\/)|\.VU($|\/)|\.WF($|\/)|\.WS($|\/)|\.XN--0ZWM56D($|\/)|\.XN--11B5BS3A9AJ6G($|\/)|\.XN--80AKHBYKNJ4F($|\/)|\.XN--9T4B11YI5A($|\/)|\.XN--DEBA0AD($|\/)|\.XN--G6W251D($|\/)|\.XN--HGBK6AJ7F53BBA($|\/)|\.XN--HLCJ6AYA9ESC7A($|\/)|\.XN--JXALPDLP($|\/)|\.XN--KGBECHTV($|\/)|\.XN--ZCKZAH($|\/)|\.YE($|\/)|\.YT($|\/)|\.YU($|\/)|\.ZA($|\/)|\.ZM($|\/)|\.ZW)/i",
    $string,
    $M);
  $has_tld = (count($M) > 0) ? true : false;
  return $has_tld;
}

function cleaner($url) {
  $U = explode(' ',$url);

  $W =array();
  foreach ($U as $k => $u) {
    if (stristr($u,".")) { //only preg_match if there is a dot    
      if (containsTLD($u) === true) {
      unset($U[$k]);
      return cleaner( implode(' ',$U));
    }      
    }
  }
  return implode(' ',$U);
}


$url = "Here is another funny site badurl.badone somesite.ca/worse.jpg but this badsite.com www.tinyurl.com/55555 and http://www.tinyurl.com/55555 and img.hostingsite.com/badpic.jpg";
echo "Cleaned: " . cleaner($url);
returns:

Cleaned: Here is another funny site badurl.badone but this and and

Free Music player for website, blogger

by in , 0

Ketnooi Music release Free new Music player for Webmasters.
You can embed K-Player to your blog, blogspot easily.
Demo see this blog
Features:
- Free music/Video for your vistors
- Easy to embed
- Light speed
- Integrate with any website, blog.
- Music is not breakable even if vistor go to new page


Just go to Video.Ketnooi.com, then create your own playlist, Save it, then get embed Code
 
Have fun!

javascript replace only first instance .replace?

by in 0

I have this
 var date = $('#Date').val();
this get the value in the textbox what would look like this
12/31/2009
Now I do this on it
var id = 'c_' + date.replace("/", '');
and the result is
c_1231/2009
It misses the last '/' I don't understand why though.

Read more »

BEST 200+ Free Responsive HTML5 templates

by in , , 0

free Collection of responsive html5 css3 templates are well-designed layout template for any kind of business, company, personal, blog, website with new html5 and css3 features! (updated 2014)

All free premium responsive Using HTML5 and CSS3 features are popular among web designers nowadays. HTML5 also provide great features to create animation on web instead of flash animation. Websites developed in HTML5 animation will not require adobe flash support on your web browser anymore, provided that your browser supports HTML5. There are more kind of html5 css3 website templates such education templates, hotel templates and more.

Free HTML5 Theme for Interior Site

Free HTML5 Theme for Business Site

Read more »

Simple Responsive Drop Down Menu jQuery CSS3

by in , 0

A beauty drop down responsive menu that shows its sub menus with icon symbol using open symbol fonts that allowing you to add more icons as you want. With my previous tutorial, i also show how to create Creating 3-Level Responsive Drop Down Navigation Menu with jQuery and CSS3 as well.
demo-drop-down-menu



Today we would like to show an experimental drop-down menu with jquery and css3 using beautiful symbol fonts. The main idea is to help you to save time for creating menus for website, it have a lot of content and sub-levels. Some sub-level in this menu will be shown in its context and icons. The menu is best use in professional web design that it can be used easily in a responsive layout.
This Responsive Drop Down Navigation Menu using plugin such as:

Read more »