php not working...any obvious errors??????
01-09-2009, 01:14 PM
|
php not working...any obvious errors??????
|
Posts: 38
Name: DB
|
I get the following error message when I try to use this script that produces thumbnails and an xml file for a flash gallery I downloaded from the net.
*<b>Warning</b>: ereg() [<a href='function.ereg'>function.ereg</a>]:*
Here is the script. Many thanks in advance for any help.
PHP Code:
<?php /* ******************************************************************************* * PHP Thumbnails and XML Creator ******************************************************************************* */ header('Content-type: text/xml'); list($list,$listStr) = getdir('./'); /* print_r($list); echo "<br/> $listStr"; echo '<hr>phpfile?'; echo ereg("php", 'asdf')?'Yes':'No'; */ //$time1=time(); $title='title'; $description='description'; $mediaXML='<?xml version="1.0" encoding="utf-8"?> <KIT3D> <images>';
$i=0; foreach ($list as $origFile) { if (!ereg("jpg", $origFile) && !ereg("JPG", $origFile)) { continue;} if (ereg("thum", $origFile)) { $thumbFile=$origFile; $origFile= str_replace('thum_','',$origFile); } else if (ereg("thum_".$origFile, $listStr)) { $thumbFile = 'thum_'.$origFile; //echo 'i='.$i++.'<br/>'; $line='<image thumbnail = "'.$thumbFile.'" image = "'.$origFile.'" title = "'.$title.'" description = "'.$description.'" /> '; $mediaXML.=$line; //echo htmlspecialchars($line).'<br/>'; } else { $thumbFile = 'thum_'.$origFile; createThumb($origFile,$thumbFile); //echo 'i='.$i++.'<br/>'; $line='<image thumbnail = "'.$thumbFile.'" image = "'.$origFile.'" title = "'.$title.'" description = "'.$description.'" /> '; $mediaXML.=$line; //echo htmlspecialchars($line).'<br/>'; } }
$mediaXML.='</images></KIT3D>'; echo $mediaXML;
$file = fopen("./media.xml","w"); fwrite($file,$mediaXML); fclose($file);
//$time=time()-$time1; //echo "--END--$time";
function createThumb($origFile,$newFile) { //echo "Creating file: $newFile";
$newWidth=240; $newHeight=240;
list($origWidth, $origHeight) = getimagesize($origFile) ;
$ratio = $origWidth/$origHeight;
if ($newWidth/$newHeight > $ratio){ $newWidth = $newHeight*$ratio; } else { $newHeight = $newWidth/$ratio; }
$thumb = imagecreatetruecolor($newWidth, $newHeight) ; $image = imagecreatefromjpeg($origFile) ; imagecopyresampled($thumb, $image, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight) ;
//Here we are saving the .jpg, you can make this gif or png if you want //the file name is set above, and the quality is set to 80% imagejpeg($thumb, $newFile, 80) ; }
function getdir($dir) { $list = array(); $listStr=''; $handle=opendir($dir); $i=0; while($file=readdir($handle)) { if (($file!=".") && ($file!="..")) { $list[$i]=$file; $i=$i+1; $listStr.=$file; } } closedir($handle); asort($list); return array($list,$listStr); } ?>
|
|
|
|
01-09-2009, 01:42 PM
|
Re: php not working...any obvious errors??????
|
Posts: 1,606
|
I copied your code above to notepad and saved that as thumb.php. When I ran it it it created an empty xml file.
So I dropped a few image in there and ran it again. It took each image and made a thumbnail and created this xml output.
Quote:
<?xml version="1.0" encoding="utf-8" ?>
- <KIT3D>
- <images>
<image thumbnail="thum_ComputerAbacus.jpg" image="ComputerAbacus.jpg" title="title" description="description" />
<image thumbnail="thum_CoolSuicide.jpg" image="CoolSuicide.jpg" title="title" description="description" />
<image thumbnail="thum_Cops.jpg" image="Cops.jpg" title="title" description="description" />
<image thumbnail="thum_CrazyDiet.jpg" image="CrazyDiet.jpg" title="title" description="description" />
<image thumbnail="thum_bbq.jpg" image="bbq.jpg" title="title" description="description" />
<image thumbnail="thum_bbq2.jpg" image="bbq2.jpg" title="title" description="description" />
<image thumbnail="thum_bonde-chick.jpg" image="bonde-chick.jpg" title="title" description="description" />
<image thumbnail="thum_buyavowel.jpg" image="buyavowel.jpg" title="title" description="description" />
<image thumbnail="thum_condodeckfinal.jpg" image="condodeckfinal.jpg" title="title" description="description" />
</images>
</KIT3D>
|
Are you sure you saved it as a php file? Notepad has a nasty habit of adding.txt to files.
PS: those files are cartoons and not porn. The blonde chick is a a chick.
|
|
|
|
01-09-2009, 01:45 PM
|
Re: php not working...any obvious errors??????
|
Posts: 38
Name: DB
|
Thanks for that very quick reply I'm on the case right now.
|
|
|
|
01-09-2009, 04:01 PM
|
Re: php not working...any obvious errors??????
|
Posts: 38
Name: DB
|
me again.... I'm sorry but I don't understand how to 'run' something. It is definitely saved as a php and I have WAMP installed. When I try to open it in a browser I get a screen full of nonsense.
|
|
|
|
01-09-2009, 04:25 PM
|
Re: php not working...any obvious errors??????
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
You say you have a wamp server, but does the eregi module is enabled in php.ini ?
I don't know wamp, but in xampp windows, several modules like pdo, xslt and curl have to be activated.
Now, as the error was a warning, maybe it was a call time error, but without the full text, it's impossible to say.
Quote:
|
When I try to open it in a browser I get a screen full of nonsense.
|
1) how do you open it? Through the web server ( http://localhost/myPage.php) or through the file system (c:\wamp\htdocs\yada\yada\myPage.php)?
2) we need informations ! Telling us it's "full of nonsense" is useless. What you refer as nonsense will surely explain us what happens.
Tell us what happens, show us what you see.
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
01-09-2009, 05:00 PM
|
Re: php not working...any obvious errors??????
|
Posts: 1,606
|
In reponse to a PM that I think should be answered in the thread for the benifit of all.
Quote:
You commented on problems I'm having with my php script... unfortunately I'm no-pro at this. I'm using WAMP and try to open the file through my browser by I get a load of nonsense. So.. how did you run it
|
I ran the script on localhost using the xampp (non-installer version). Computer is running windows XP if that might matter.
It is using php5+ and whatever the default install is for image handling. I do know that register_globals and safe_mode are off in the directory in which I ran it.
I ran the script from the browser. There is no index page in the directory where I placed it.
I can and will run phpinfo and post those results if Tripy or you thinks it might help you.
|
|
|
|
01-09-2009, 05:02 PM
|
Re: php not working...any obvious errors??????
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Quote:
|
I can and will run phpinfo and post those results if Tripy or you thinks it might help you.
|
I don't think it would any useful info for the moment, but thanks Colbyt.
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
01-09-2009, 05:13 PM
|
Re: php not working...any obvious errors??????
|
Posts: 1,606
|
I am thinking that he copied this script from a web page and did not take the curse off.
Here is the script in a zipfile. Download this and try running it on your machine.
|
|
|
|
01-09-2009, 06:06 PM
|
Re: php not working...any obvious errors??????
|
Posts: 38
Name: DB
|
Ok.... sorry for being so vague.
I am trying to use a flash gallery on a website. The php is to make thumbnails. On my web server I get this error
*<b>Warning</b>: ereg() [<a href='function.ereg'>function.ereg</a>]:*
Then after contacting them they said all is well with their system and no changes have been made recently.
With regards to problem solving here on my PC. I installed WAMP on XP and tried again to use the photo gallery. Instructions say that thumb.php should be in the same folder as the images and open through the browser. So I use my browser to go into the file via the localhost method and this is what comes up in firefox....
Code:
$listStr"; echo 'phpfile?'; echo ereg("php", 'asdf')?'Yes':'No'; */ //$time1=time(); $title='title'; $description='description'; $mediaXML=' '; $i=0; foreach ($list as $origFile) { if (!ereg("jpg", $origFile) && !ereg("JPG", $origFile)) { continue;} if (ereg("thum", $origFile)) { $thumbFile=$origFile; $origFile= str_replace('thum_','',$origFile); } else if (ereg("thum_".$origFile, $listStr)) { $thumbFile = 'thum_'.$origFile; //echo 'i='.$i++.'
'; $line='<img thumbnail="'.$thumbFile.'" image="'.$origFile.'" title="'.$title.'" description="'.$description.'"> '; $mediaXML.=$line; //echo htmlspecialchars($line).'
'; } else { $thumbFile = 'thum_'.$origFile; createThumb($origFile,$thumbFile); //echo 'i='.$i++.'
'; $line='<img thumbnail="'.$thumbFile.'" image="'.$origFile.'" title="'.$title.'" description="'.$description.'"> '; $mediaXML.=$line; //echo htmlspecialchars($line).'
'; } } $mediaXML.=''; echo $mediaXML; $file = fopen("./media.xml","w"); fwrite($file,$mediaXML); fclose($file); //$time=time()-$time1; //echo "--END--$time"; function createThumb($origFile,$newFile) { //echo "Creating file: $newFile"; $newWidth=240; $newHeight=240; list($origWidth, $origHeight) = getimagesize($origFile) ; $ratio = $origWidth/$origHeight; if ($newWidth/$newHeight > $ratio){ $newWidth = $newHeight*$ratio; } else { $newHeight = $newWidth/$ratio; } $thumb = imagecreatetruecolor($newWidth, $newHeight) ; $image = imagecreatefromjpeg($origFile) ; imagecopyresampled($thumb, $image, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight) ; //Here we are saving the .jpg, you can make this gif or png if you want //the file name is set above, and the quality is set to 80% imagejpeg($thumb, $newFile, 80) ; } function getdir($dir) { $list = array(); $listStr=''; $handle=opendir($dir); $i=0; while($file=readdir($handle)) { if (($file!=".") && ($file!="..")) { $list[$i]=$file; $i=$i+1; $listStr.=$file; } } closedir($handle); asort($list); return array($list,$listStr); } ?>
The gallery is located here ........
www.kit3d.com/
I hope I have missed anything out.
Thanks.
DB
|
|
|
|
01-09-2009, 06:56 PM
|
Re: php not working...any obvious errors??????
|
Posts: 1,606
|
Did you download the zipfile above, unzip it and run it?
What did you use to upload the file to your server? cPnanel can mess them. FTP in auto mode is the best way.
What I think you are doing is running a file with artifacts of broken tags because you copied it staight from a web page to your file. Scripts on web pages, even those that are in text boxes sometimes have formatting characters in them.
The text your browser is displaying is actually text that is remarked out in the script. Hence my reasoning.
Be sure to force the reload on the page once you try the new version. FF does not auto refresh.
Last edited by colbyt; 01-09-2009 at 06:58 PM..
|
|
|
|
01-09-2009, 07:38 PM
|
Re: php not working...any obvious errors??????
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
As colbyt said...
What you see is the PHP source code, the program.
This means that the web server did not have "seen" where it started and has not interpreted this code.
That's the reason why you see it as text.
HTML is a descriptive language. It means that you use a language to describe to another program how to display something.
The fact is, that when you see the character "<", you have 85% of chances that it's not really what is under, but only the result of the description.
As "<" and ">" are used in the html source, their litteral values have an equivalent, which is known as an entity.
it's > for ">" and < for "<"
If you copy some source code from a web page, you probably have copied the entity, and not the result of the entity.
As the web server sends to php only what is contained between <?php and ?>, it will miss what is between >?php and <
It's probably your problem.
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
01-09-2009, 09:20 PM
|
Re: php not working...any obvious errors??????
|
Posts: 38
Name: DB
|
Ok... a new update.
Following all the above instructions and advice I ran the new thumb.php through my browser ( localhost/ ) in a folder with a load of images. It made the thumbnails but then give this error.
Code:
XML Parsing Error: junk after document element
Location: http://localhost/tattoomany/media/thumb.php
Line Number 2, Column 1:<b>Warning</b>: ereg() [<a href='function.ereg'>function.ereg</a>]: REG_EBRACK in <b>C:\wamp\www\tattoomany\media\thumb.php</b> on line <b>28</b><br />
^
In WAMP there are a load of modules ticked for apache but I honestly have no idea which ones should and shouldn't be ticked. php5 is ticked/on.
Is there any other way to make the xml file for this? I now have all the thumbs but no xml.
Thanks
|
|
|
|
01-10-2009, 07:50 AM
|
Re: php not working...any obvious errors??????
|
Posts: 1,606
|
This is just a guess. One or more of your filenames contained un-allowed characters. Make sure that no filename contains anything other than 0-9, a-z and hyphens. Replace any _ with a hypen though surely the script could handle that since it adds them for the thumbs.
You can always hand code an xml file. It is just like html with different <tags>.
I doubt you need to change any settings on your WAMP install.
|
|
|
|
01-11-2009, 07:10 AM
|
Re: php not working...any obvious errors??????
|
Posts: 38
Name: DB
|
Colbyt and Tripy, thanks for your help. I'm happy to say that the problem is now fixed..........
Colbyt - you hit the nail on the head. I used an image re-sizer and it labelled all my images , for example, image1[].jpg image2[].jpg, because the originals were kept. When I removed the tags/brackets everything worked as it should.
I wasn't only able to solve this problem but have learn't how to post a problem here in the forum correctly, the inside of WAMP and more about php.
Many thanks guys.
DB
|
|
|
|
01-11-2009, 07:43 AM
|
Re: php not working...any obvious errors??????
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Good call colbyt, I was inspecting the file for the last 10 minutes before checking here.
And glad you could have your script running before your class, pathfinder.
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
|
« Reply to php not working...any obvious errors??????
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|