getimagesize() working and *not*working... why?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ja NE

    getimagesize() working and *not*working... why?

    (as first - thank you for all your help several years ago, and second - please
    apologise me for my clumsy enlgish)

    so, preface: some users on my photo related site sometimes enter (link) giant
    photo in their post or coment, and while I was writting new bbcode for my
    forum, I have got idea to check size of linked pictures to scale them down if
    needed (matamethic of that part isn't written in folowing code and would not
    be a problem).

    and now, the problem: function getimagesize() worked fine while getting data
    from my other domains on same server, I tested it with some from other servers
    and worked fine... but just until I called that function from other function
    in my semi-finished page. All I get is "Warning:
    getimagesize("h ttp://bla.bla./bla.img") [function.getima gesize]: failed to
    open stream: No such file or directory in my.script.php on line 3". But - you
    will be able to see that same function (getimagesize() ) *is* working on the
    same page called alone... what went wrong? what am I not seeing?

    I will paste two scripts (some commnets and variables have been written in
    croatish, hope that that wont be a problem), the testing one - where function
    after submit button isn't working (script includes whole yet written
    formatings), and the first one (coding) where I coded that functions...

    people interested in solving my problem can see scripts in function and their
    source (if my newsreader won't post code properly):






    thank you for all your help.
    Janko.

    testing.php: //start

    <?phpfunction pict_size($path ) { list($width, $height, $type, $attr) =
    getimagesize($p ath); $size=" width=" . ceil($width/2) . " height=" .
    ceil($height/2) . " "; return $size;}function bbcode_format($ newtxt) {
    // global $path; // cut mysql slash $newtxt = stripslashes($n ewtxt);
    // change bbcode $bbkod = array(
    '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is',
    '/\[url\=(.*?)=url\](.*?)\[\/url\]/is', '/\[img=(.*?)\
    img\]/is', '/\r\n/is' ); $htmlkod =
    array( '<b>$1</b>', '<i>$1</i>',
    '<a href="$1">$2</a>', '</p><img src="$1" /><p>',
    '</p><p>' ); $newtxt = preg_replace($b bkod, $htmlkod,
    $newtxt); // in case of tooooo big photos // geting pict sources
    preg_match_all( '/src=(.*?) \/>/i', $newtxt, $matches, PREG_SET_ORDER) ;
    //slazem arraye prije i poslije $i=0; // probably not needed, but makes me
    sure foreach ($matches as $val) { $i++; $path =
    trim($val[1]); $nums = pict_size($path ); $all = $val[1] .
    "$nums"; $base[$i]=$val[1]; ksort($base); $new[$i]=$all;
    ksort($new); } $newtxt = str_replace($ba se, $new, $newtxt); return
    $newtxt;}// starting test html page with JSecho"<?xml version=\"1.0\"
    encoding=\"UTF-8\" ?>\n\n";?><!DOC TYPE html PUBLIC "-//W3C//DTD XHTML 1.0
    Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>novi bbcode</title><script type="text/javascript">fun ction
    getSelection(ta ) { var bits = [ta.value,'','', ''];
    if(document.sel ection) { var vs = '#$%^%$#'; var
    tr=document.sel ection.createRa nge() if(tr.parentEle ment()!=ta) return
    null; bits[2] = tr.tekst; tr.tekst = vs; fb =
    ta.value.split( vs); tr.moveStart('c haracter',-vs.length);
    tr.tekst = bits[2]; bits[1] = fb[0]; bits[3] = fb[1]; }
    else { if(ta.selection Start == ta.selectionEnd ) return null;
    //pu¹ten u promet unicode raspon od null do zadnjeg latin modifier znaka,
    slijedili bi grèki, koptski, æirilica... bits=(new RegExp('([\u0000-\u0
    2FE]{'+ta.selection Start+'})([\u0000-\u02FE]{'+(ta.selectio nEnd
    - ta.selectionSta rt)+'})([\u0000-\u02FE]*)')).exec(ta.v alue); } return
    bits;}function matchPTags(str) { str = ' ' + str + ' '; ot =
    str.split(/\[[b|url|i].*?\]/i); ct = str.split(/\[\/[b|url|i].*?\]/i);
    return ot.length==ct.l ength;}function addPTag(ta,pTag ){ bits =
    getSelection(ta ); if(bits) { if(!matchPTags( bits[2])) {
    alert('\tNEPRAV ILNA SELEKCIJA\nSele kcija sadr¾i druge poèetne ili zavr¹e
    tagove!.'); return; } ta.value = bits[1] + '[' + pTag
    + ']' + bits[2] + '[/' + pTag + ']' + bits[3]; }}function
    addUriTag(ta,pT ag){ bits = getSelection(ta ); var original = bits[2];
    var trazim = "http://"; if(bits) { if(!matchPTags( bits[2])) {
    alert('\tNEPRAV ILNA SELEKCIJA\nSele kcija sadr¾i druge poèetne ili zavr¹e
    tagove!.'); return; } if(original.mat ch(trazim) ==
    null) { noviuri = 'http://' + bits[2]; } else {
    noviuri = bits[2] } ta.value = bits[1] + '[' + pTag + '=' +
    noviuri + '=' + pTag + ']' + bits[2] + '[/' + pTag + ']' + bits[3]; }}
    function bburl(){ var adresa = prompt("Upi¹ite adresu stranice
    poput:\nhttp://www.moj_site.co m/stranica.html") ; var trazim = "http://";
    if(adresa==null || adresa==0 || adresa=='') { alert('(prazna veza nije
    unesena)'); return; } if(adresa.match (trazim) == null) {
    noviuri = 'http://' + adresa; } else { noviuri = adresa; }
    var naziv = prompt("Upi¹ite tekst linka (naziv veze):"); if(naziv==null ||
    naziv==0 || naziv=='') { novinaziv = adresa; } else {
    novinaziv = naziv; } document.komuni kacija.tekst.va lue+="
    "+novinaziv +" ";}
    function bbimg(){ var izvor = prompt("Upi¹ite adresu slike (ne stranice na
    kojoj je slika!):"); var trazim = "http://"; if(izvor==null || izvor==0
    || izvor=='') { alert('(prazna veza nije unesena)'); return;
    } if(izvor.match( trazim) == null) { urislike = 'http://' + izvor;
    } else { urislike = izvor; }
    document.komuni kacija.tekst.va lue+=" [img="+urislike+ " img] ";}function
    ReloadTextDiv() { var NewText = document.getEle mentById("tekst ").value;
    NewText = NewText.replace (/\[url=/g, "<a href="); NewText =
    NewText.replace (/\[\/url\]/g, "<\/a>"); NewText =
    NewText.replace (/=url\]/g, ">"); NewText = NewText.replace (/\[img=/g, "<img
    src="); NewText = NewText.replace (/img\]/g, " />"); NewText =
    NewText.replace (/\[b\]/g, "<b>"); NewText = NewText.replace (/\[\/b\]/g,
    "<\/b>"); NewText = NewText.replace (/\[i\]/g, "<i>"); NewText =
    NewText.replace (/\[\/i\]/g, "<\/i>"); splitText = NewText.split(/\n/);
    var DivElement = document.getEle mentById("prevj u"); var i = 0;
    DivElement.inne rHTML = ''; for(i = 0; i < splitText.lengt h; i++) {
    if(splitText[i].length 0 ) { DivElement.inne rHTML += splitText[i] +
    "<br />"; } }}function provjeraUnosa(f orm) { //unfinished var
    naslov = 'let us see<hr>'; var unos = '' + form.tekst.valu e + ''; win =
    window.open('', '','width=400,h eight=400,toolb ar=1,location=1 ,directories=1, sta
    tus=1,scrollbar s=1,men
    ubar=1,resizabl e=1'); unos = unos.replace(/\[url=/g, "<a href="); unos
    = unos.replace(/url\]/g, "\a>"); unos = unos.replace(/\[img=/g, "<img
    src="); unos = unos.replace(/img\]/g, " />"); unos = unos.replace(/\[/g,
    "<"); unos = unos.replace(/\]/g, ">"); win.document.wr ite('<tt>' +
    naslov + '</tt>\n<p>' + unos + '</p>'); win.document.cl ose();}</script>
    </head><body style="backgrou nd-color: gray;"><?if($_P OST['tekst']) { $tekst
    = $_POST['tekst']; $tekst = strip_tags($tek st); $tekst =
    htmlspecialchar s($tekst, ENT_QUOTES); if (!get_magic_quo tes_gpc()) {
    $tekst = addslashes($tek st); } else { $tekst = $tekst; }
    echo"<tt>what we can get from mysql query one day:<br />\n$tekst\n</tt><hr
    />\n"; $prikaz = bbcode_format($ tekst); echo"$prikaz";} else {?>
    <h1>new bbcode</h1 <p>still writing &amp; testing</p><script
    type="text/javascript"><!--document.write( "<fieldset> ");
    document.write( "<button
    onclick=\"addPT ag(document.get ElementById('te kst'),'b');
    ReloadTextDiv() ;\">");document .write("<b>bold </b>");
    document.write( "</button>");docum ent.write("<but ton
    onclick=\"addPT ag(document.get ElementById('te kst'),'i');
    ReloadTextDiv() ;\">");document .write("<i>ital ic</i>");
    document.write( "</button>");docum ent.write("<but ton
    onclick=\"addUr iTag(document.g etElementById(' tekst'),'url');
    ReloadTextDiv() ;\">");document .write("<span style=\"tekst-decoration:
    underline;\">ma ke url</span>");documen t.write("</button>");
    document.write( "<button
    onclick=\"bburl (document.getEl ementById('teks t'),'url');
    ReloadTextDiv() ;\">");document .write("<span style=\"tekst-decoration:
    underline;\">in put url</span>");documen t.write("</button>");
    document.write( "<button
    onclick=\"bbimg (document.getEl ementById('teks t'),'img');
    ReloadTextDiv() ;\">");document .write("<span style=\"tekst-decoration:
    underline;\">in put image</span>");documen t.write("</button>");
    document.write( "</fieldset>");//--></script <noscript><p>bl a bla, yr
    browser != JS, writte [tag][/yrslf]</p></noscript <form
    name="komunikac ija" id="komunikacij a" action="<?= $PHP_SELF; ?>"
    method="post" <textarea name="tekst" id="tekst" rows="20" cols="60"
    onkeyup="Reload TextDiv();">[img=http://nastamba.net/samobor.jpg
    img]</textarea <p <input disabled="disab led" name="provjera"
    type="button" class="submit" value="provjera "
    onclick="provje raUnosa(this.fo rm)" /&nbsp; <input type="submit" />
    </p </form <div id="prevju" style="backgrou nd-color: white;
    width:600px; height:auto;" </div><?}echo"<hr />\n<p>line to test
    getimagesize() alone</p>\n";list($wid th, $height, $type, $attr) =
    getimagesize(tr im('http://nastamba.net//kalnik.jpg'));e cho"<img
    src='http://nastamba.net/kalnik.jpg' $attr />\n";?></body></html>

    end.testing

    coding.php: //start
    <?phpfunction pict_size($path ) { list($width, $height, $type, $attr) =
    getimagesize($p ath); $size=" width=" . ceil($width/2) . " height=" .
    ceil($height/2) . " "; return $size;} $one = "<p>I have some pictures in
    sitring, dont know how many of them, dont know how big they can be</p>\n<img
    src=http://nastamba.net/kalnik.jpg />\n<br />\n<img
    src=http://www.nastamba.ne t/samobor.jpg />\n<p>\nSo I need to get their size
    and print them smaller sometimes.</p>\n";echo "$one\n";ec ho "<hr>\n"; // cut
    $two = htmlspecialchar s($one);echo "<tt><em>ju st showing html code to
    myself:</em><br />$two<br />Now I will look for source of pictures, get their
    sizes and scale them. For test only.</tt>\n";echo "<hr>\n"; // cutecho
    "<pre>\n"; // formatpreg_matc h_all('/src=(.*?) \/>/i', $one, $matches,
    PREG_SET_ORDER) ;$i=0; // probably not needed, but makes me sureforeach
    ($matches as $val) { $i++; $path = trim($val[1]); $nums =
    pict_size($path ); $all = $val[1] . "$nums"; $base[$i]=$val[1];
    ksort($base); $new[$i]=$all; ksort($new);}// to see what we got
    print_r($base); print_r($new);e cho "</pre>\n"; // formatecho"<hr> \n"; // cut
    $resized = str_replace($ba se, $new, $one);echo "<tt><em>(l et us just asume
    that those were 2 giants photos in our string)</em><br>$resized \n";echo
    "<hr>\n"; // cut$three = htmlspecialchar s($resized);ech o "<tt><em>ag ain just
    showing html code to myself:</em><br />$three</tt>\n";echo "<hr>\n"; // cut?>

    end.coding
  • Ja NE

    #2
    Re: getimagesize() working and *not*working... why?

    Ja NE wrote:
    testing.php: //start
    end.coding
    ouch? :(
    what a mess? (at least in my reader) ?sorry for that.

    Comment

    • Paul Lautman

      #3
      Re: getimagesize() working and *not*working... why?

      Ja NE wrote:
      Ja NE wrote:
      >
      >testing.php: //start
      >end.coding
      >
      ouch? :(
      what a mess? (at least in my reader) ?sorry for that.
      Yes you are right, it is too much of a mess to even try to understand it.

      However, the error is telling you that http://bla.bla./bla.img cannot be
      found.


      Comment

      • Ja NE

        #4
        Re: getimagesize() working and *not*working... why?

        Paul Lautman wrote:
        Ja NE wrote:
        >Ja NE wrote:
        >>
        >>testing.php : //start
        >>end.coding
        >>
        >ouch? :(
        >what a mess? (at least in my reader) ?sorry for that.
        >
        Yes you are right, it is too much of a mess to even try to understand it.
        >
        However, the error is telling you that http://bla.bla./bla.img cannot be
        found.
        yes, I know that, but whay? Why in one line of code but not in the other line?

        here is another, way shorter attempt,
        (changed LF to CRLF, hope this will help):

        <?php
        function pict_size($path ) {
        list($w,$h,$t,$ a) = getimagesize($p ath);
        $size=" width=" . ceil($w/2) . " height=" . ceil($h/2) . " ";
        return $size;
        }
        function bbcode_format($ newtxt) {
        $newtxt = stripslashes($n ewtxt);
        $bbkod = array(
        '/\[b\](.*?)\[\/b\]/is',
        '/\[i\](.*?)\[\/i\]/is',
        '/\[url\=(.*?)=url\](.*?)\[\/url\]/is',
        '/\[img=(.*?)\ img\]/is',
        '/\r\n/is');
        $htmlkod = array(
        '<b>$1</b>',
        '<i>$1</i>',
        '<a href="$1">$2</a>',
        '</p><img src="$1" /><p>',
        '</p><p>');
        $newtxt = preg_replace($b bkod, $htmlkod, $newtxt);
        preg_match_all( '/src=(.*?) \/>/i', $newtxt, $matches, PREG_SET_ORDER) ;
        $i=0; // probably not needed, but makes me sure
        foreach ($matches as $val) {
        $i++;
        $path = trim($val[1]);
        $nums = pict_size($path );
        $all = $val[1] . "$nums";
        $base[$i]=$val[1];
        ksort($base);
        $new[$i]=$all;
        ksort($new);
        }
        $newtxt = str_replace($ba se, $new, $newtxt);
        return $newtxt;
        }
        if($_POST['tekst']) {
        $tekst = $_POST['tekst'];
        $tekst = strip_tags($tek st);
        $tekst = htmlspecialchar s($tekst, ENT_QUOTES);
        if (!get_magic_quo tes_gpc()) {
        $tekst = addslashes($tek st);
        } else {
        $tekst = $tekst;
        }
        echo"what we can get from mysql query one day:<br>$tekst< br>";
        $prikaz = bbcode_format($ tekst);
        echo"$prikaz";}
        else {
        ?>
        <form action="<?= $PHP_SELF; ?>" method="post">
        <textarea name="tekst" id="tekst" rows="5" cols="60">
        [img=http://nastamba.net/kalnik.jpg img]
        </textarea>
        <br>
        <input type="submit" />
        </form>
        <?php
        }
        echo"line to test getimagesize() alone with :".
        "list(\$w,\$h,\ $t,\$a) =
        getimagesize('h ttp://nastamba.net/kalnik.jpg');<b r>";
        list($w,$h,$t,$ a) = getimagesize(tr im('http://nastamba.net/kalnik.jpg'));
        echo"<img src='http://nastamba.net/kalnik.jpg' $a />";?>

        for those who are not afraid to click:
        http://nastamba.net/short.php.txt
        and
        http://nastamba.net/short.php

        Comment

        • Ja NE

          #5
          Re: getimagesize() working and *not*working... why?

          OK, this time it was almoast perfect copy-paste :)

          so, the following line (#3) "isnt working"
          list($w,$h,$t,$ a) = getimagesize($p ath);
          I'm calling it in function starting at line #7
          function bbcode_format($ newtxt) {
          in line #27
          $nums = pict_size($path );
          which itself is called after submit button action in line #47
          $prikaz = bbcode_format($ tekst);
          but(!), the "same" function on line 63 is working with the very same picture!
          list($w,$h,$t,$ a) = getimagesize(tr im('http://nastamba.net/kalnik.jpg'));
          why is that?

          Comment

          • Jerry Stuckle

            #6
            Re: getimagesize() working and *not*working... why?

            Ja NE wrote:
            OK, this time it was almoast perfect copy-paste :)
            >
            so, the following line (#3) "isnt working"
            > list($w,$h,$t,$ a) = getimagesize($p ath);
            >
            I'm calling it in function starting at line #7
            >function bbcode_format($ newtxt) {
            in line #27
            > $nums = pict_size($path );
            which itself is called after submit button action in line #47
            > $prikaz = bbcode_format($ tekst);
            >
            but(!), the "same" function on line 63 is working with the very same picture!
            >list($w,$h,$t, $a) = getimagesize(tr im('http://nastamba.net/kalnik.jpg'));
            >
            why is that?
            >
            Probably because the filename you're passing is not what you expect.
            Try echoing the filename from your bbcode_format() function.

            Also, why are you using addslashes()? If you're on a good server,
            magic_quotes_gp c() should be off, so you shouldn't need to check it.
            But if you do need to check it, all you should have to do is call
            stripslashes() if it's on.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • Ja NE

              #7
              Re: getimagesize() working and *not*working... why?

              Jerry Stuckle wrote:
              Ja NE wrote:
              >OK, this time it was almoast perfect copy-paste :)
              >>
              >so, the following line (#3) "isnt working"
              >> list($w,$h,$t,$ a) = getimagesize($p ath);
              >>
              >I'm calling it in function starting at line #7
              >>function bbcode_format($ newtxt) {
              >in line #27
              >> $nums = pict_size($path );
              >which itself is called after submit button action in line #47
              >> $prikaz = bbcode_format($ tekst);
              >>
              >but(!), the "same" function on line 63 is working with the very same
              picture!
              >>list($w,$h,$t ,$a) = getimagesize(tr im('http://nastamba.net/kalnik.jpg'));
              >>
              >why is that?
              >>
              >
              Probably because the filename you're passing is not what you expect.
              Try echoing the filename from your bbcode_format() function.
              >
              yes - that was a problem. just checked minute ago echoing in the function
              pict_size() and I'w got $path with quotes from line 19 in bbcode_format
              function: '</p><img src="$1" /><p>', stupid and bizare mistake... :)
              Also, why are you using addslashes()? If you're on a good server,
              magic_quotes_gp c() should be off, so you shouldn't need to check it.
              But if you do need to check it, all you should have to do is call
              stripslashes() if it's on.
              akhm, khm... well, I'll check on that - I'm not programer, just photographer
              who decided to use php to develop and maintain one (10 years old! :)) photo
              comunity.

              tnx for support once again :D

              Comment

              • Jerry Stuckle

                #8
                Re: getimagesize() working and *not*working... why?

                Ja NE wrote:
                Jerry Stuckle wrote:
                >Ja NE wrote:
                >>OK, this time it was almoast perfect copy-paste :)
                >>>
                >>so, the following line (#3) "isnt working"
                >>> list($w,$h,$t,$ a) = getimagesize($p ath);
                >>I'm calling it in function starting at line #7
                >>>function bbcode_format($ newtxt) {
                >>in line #27
                >>> $nums = pict_size($path );
                >>which itself is called after submit button action in line #47
                >>> $prikaz = bbcode_format($ tekst);
                >>but(!), the "same" function on line 63 is working with the very same
                picture!
                >>>list($w,$h,$ t,$a) = getimagesize(tr im('http://nastamba.net/kalnik.jpg'));
                >>why is that?
                >>>
                >Probably because the filename you're passing is not what you expect.
                >Try echoing the filename from your bbcode_format() function.
                >>
                >
                yes - that was a problem. just checked minute ago echoing in the function
                pict_size() and I'w got $path with quotes from line 19 in bbcode_format
                function: '</p><img src="$1" /><p>', stupid and bizare mistake... :)
                >
                >Also, why are you using addslashes()? If you're on a good server,
                >magic_quotes_g pc() should be off, so you shouldn't need to check it.
                >But if you do need to check it, all you should have to do is call
                >stripslashes () if it's on.
                >
                akhm, khm... well, I'll check on that - I'm not programer, just photographer
                who decided to use php to develop and maintain one (10 years old! :)) photo
                comunity.
                >
                tnx for support once again :D
                >
                You are a programmer, whether an amateur or professional.

                But you really need to understand what's going on. Things like SQL
                injection, quite easy to do if you don't add the appropriate safeguards,
                can be quite damaging to your site, your reputation and even possibly
                your customers.

                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                Working...