473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 5134
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: lawrence | last post by:
I'm a beginner with Javascript and especially cross-browser Javascript. I got this working in IE, but not in Netscape 7. It seems like, in Netscape, every time I click on a button, the focus shifts...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
by: dBNovice | last post by:
Hi all, I am reusing code that was used in a previous copy of the DB. I am trying to extract data from other tables, queries and a form and put it in a table. The code was used previously and...
14
by: menakasrinivasagam | last post by:
my coding is working in mozilla firefox.but not working in Internet explorer.plz give suggestion to rectify this problem
33
by: buss123 | last post by:
Hi all, combo box script code was working in IE perfectly with all modes but OnChange event was not working in FireFox(editable mode, if we select valuese that combo box values r...
3
by: shyamg | last post by:
hi all, This javascript is working IE but not working in FIreFox, validating text fields. var dealerid = new keybEdit('abcdefghijklmnopqurstuvwxyz01234567890 ','Alpha-numeric input only.'); ...
3
by: rajasree | last post by:
Hi all, am doing a project in PHP. my javascript code is working properly in ie. But its not working in firefox. Please help me my code is as follows; <script language="javascript"...
1
by: itskaps | last post by:
Hi all, My following program code works fine on win 2K server but the same is not working on win2K3 server. It's showing error as page cannot be displayed. After debugging, I found that...
4
by: mport | last post by:
Does anyone know of possible reasons why onload might not be working? It's gotta be the most pathetic question ever, it's doing my head in!! I've done this a dozen times, but on this one, nothing! I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.