(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 & 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)" / <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