470,848 Members | 1,111 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

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("http://bla.bla./bla.img") [function.getimagesize]: 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):

http://nastamba.net/coding.php
http://nastamba.net/coding.php.txt
http://nastamba.net/testing.php
http://nastamba.net/testing.php.txt

thank you for all your help.
Janko.

testing.php: //start

<?phpfunction pict_size($path) { list($width, $height, $type, $attr) =
getimagesize($path); $size=" width=" . ceil($width/2) . " height=" .
ceil($height/2) . " "; return $size;}function bbcode_format($newtxt) {
// global $path; // cut mysql slash $newtxt = stripslashes($newtxt);
// 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($bbkod, $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($base, $new, $newtxt); return
$newtxt;}// starting test html page with JSecho"<?xml version=\"1.0\"
encoding=\"UTF-8\" ?>\n\n";?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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">function
getSelection(ta) { var bits = [ta.value,'','',''];
if(document.selection) { var vs = '#$%^%$#'; var
tr=document.selection.createRange() if(tr.parentElement()!=ta) return
null; bits[2] = tr.tekst; tr.tekst = vs; fb =
ta.value.split(vs); tr.moveStart('character',-vs.length);
tr.tekst = bits[2]; bits[1] = fb[0]; bits[3] = fb[1]; }
else { if(ta.selectionStart == 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.selectionStart+'})([\u0000-\u02FE]{'+(ta.selectionEnd
- ta.selectionStart)+'})([\u0000-\u02FE]*)')).exec(ta.value); } 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.length;}function addPTag(ta,pTag){ bits =
getSelection(ta); if(bits) { if(!matchPTags(bits[2])) {
alert('\tNEPRAVILNA SELEKCIJA\nSelekcija sadrži druge početne ili završe
tagove!.'); return; } ta.value = bits[1] + '[' + pTag
+ ']' + bits[2] + '[/' + pTag + ']' + bits[3]; }}function
addUriTag(ta,pTag){ bits = getSelection(ta); var original = bits[2];
var trazim = "http://"; if(bits) { if(!matchPTags(bits[2])) {
alert('\tNEPRAVILNA SELEKCIJA\nSelekcija sadrži druge početne ili završe
tagove!.'); return; } if(original.match(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.com/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.komunikacija.tekst.value+="
"+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.komunikacija.tekst.value+=" [img="+urislike+" img] ";}function
ReloadTextDiv() { var NewText = document.getElementById("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.getElementById("prevju"); var i = 0;
DivElement.innerHTML = ''; for(i = 0; i < splitText.length; i++) {
if(splitText[i].length 0 ) { DivElement.innerHTML += splitText[i] +
"<br />"; } }}function provjeraUnosa(form) { //unfinished var
naslov = 'let us see<hr>'; var unos = '' + form.tekst.value + ''; win =
window.open('','','width=400,height=400,toolbar=1, location=1,directories=1,sta
tus=1,scrollbars=1,men
ubar=1,resizable=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.write('<tt>' +
naslov + '</tt>\n<p>' + unos + '</p>'); win.document.close();}</script>
</head><body style="background-color: gray;"><?if($_POST['tekst']) { $tekst
= $_POST['tekst']; $tekst = strip_tags($tekst); $tekst =
htmlspecialchars($tekst, ENT_QUOTES); if (!get_magic_quotes_gpc()) {
$tekst = addslashes($tekst); } 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=\"addPTag(document.getElementById('tekst') ,'b');
ReloadTextDiv();\">");document.write("<b>bold</b>");
document.write("</button>");document.write("<button
onclick=\"addPTag(document.getElementById('tekst') ,'i');
ReloadTextDiv();\">");document.write("<i>italic</i>");
document.write("</button>");document.write("<button
onclick=\"addUriTag(document.getElementById('tekst '),'url');
ReloadTextDiv();\">");document.write("<span style=\"tekst-decoration:
underline;\">make url</span>");document.write("</button>");
document.write("<button
onclick=\"bburl(document.getElementById('tekst'),' url');
ReloadTextDiv();\">");document.write("<span style=\"tekst-decoration:
underline;\">input url</span>");document.write("</button>");
document.write("<button
onclick=\"bbimg(document.getElementById('tekst'),' img');
ReloadTextDiv();\">");document.write("<span style=\"tekst-decoration:
underline;\">input image</span>");document.write("</button>");
document.write("</fieldset>");//--></script <noscript><p>bla bla, yr
browser != JS, writte [tag][/yrslf]</p></noscript <form
name="komunikacija" id="komunikacija" action="<?= $PHP_SELF; ?>"
method="post" <textarea name="tekst" id="tekst" rows="20" cols="60"
onkeyup="ReloadTextDiv();">[img=http://nastamba.net/samobor.jpg
img]</textarea <p <input disabled="disabled" name="provjera"
type="button" class="submit" value="provjera"
onclick="provjeraUnosa(this.form)" /&nbsp; <input type="submit" />
</p </form <div id="prevju" style="background-color: white;
width:600px; height:auto;" </div><?}echo"<hr />\n<p>line to test
getimagesize() alone</p>\n";list($width, $height, $type, $attr) =
getimagesize(trim('http://nastamba.net//kalnik.jpg'));echo"<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($path); $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.net/samobor.jpg />\n<p>\nSo I need to get their size
and print them smaller sometimes.</p>\n";echo "$one\n";echo "<hr>\n"; // cut
$two = htmlspecialchars($one);echo "<tt><em>just 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_match_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);echo "</pre>\n"; // formatecho"<hr>\n"; // cut
$resized = str_replace($base, $new, $one);echo "<tt><em>(let us just asume
that those were 2 giants photos in our string)</em><br>$resized\n";echo
"<hr>\n"; // cut$three = htmlspecialchars($resized);echo "<tt><em>again just
showing html code to myself:</em><br />$three</tt>\n";echo "<hr>\n"; // cut?>

end.coding
Jun 2 '08 #1
7 4934
Ja NE wrote:
testing.php: //start
end.coding
ouch? :(
what a mess? (at least in my reader) ?sorry for that.
Jun 2 '08 #2
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.
Jun 2 '08 #3
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($path);
$size=" width=" . ceil($w/2) . " height=" . ceil($h/2) . " ";
return $size;
}
function bbcode_format($newtxt) {
$newtxt = stripslashes($newtxt);
$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($bbkod, $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($base, $new, $newtxt);
return $newtxt;
}
if($_POST['tekst']) {
$tekst = $_POST['tekst'];
$tekst = strip_tags($tekst);
$tekst = htmlspecialchars($tekst, ENT_QUOTES);
if (!get_magic_quotes_gpc()) {
$tekst = addslashes($tekst);
} 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('http://nastamba.net/kalnik.jpg');<br>";
list($w,$h,$t,$a) = getimagesize(trim('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
Jun 2 '08 #4
OK, this time it was almoast perfect copy-paste :)

so, the following line (#3) "isnt working"
list($w,$h,$t,$a) = getimagesize($path);
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(trim('http://nastamba.net/kalnik.jpg'));
why is that?
Jun 2 '08 #5
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($path);

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(trim('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_gpc() 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.
js*******@attglobal.net
==================

Jun 2 '08 #6
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($path);

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(trim('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_gpc() 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
Jun 2 '08 #7
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($path);
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(trim('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_gpc() 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.
js*******@attglobal.net
==================

Jun 2 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Martin Heuckeroth | last post: by
4 posts views Thread by mport | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.