<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Just answer the F*#king question &#187; PHP</title>
	<atom:link href="http://www.jatfq.com/archives/category/usefull-stuff/php-stuff/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jatfq.com</link>
	<description>Saving the world from dicks with forum logins ...</description>
	<pubDate>Mon, 03 Nov 2008 17:18:18 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>Serve JAD files OTA with PHP</title>
		<link>http://www.jatfq.com/archives/62</link>
		<comments>http://www.jatfq.com/archives/62#comments</comments>
		<pubDate>Mon, 03 Nov 2008 17:14:41 +0000</pubDate>
		<dc:creator>Sime</dc:creator>
		
		<category><![CDATA[J2ME]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jatfq.com/?p=62</guid>
		<description><![CDATA[Some handy code to dynamtically serve JAD files for OTA installation. The below script sets the appropriate headers types, also tidies up the JAD file removing stray characters which can cause issues and setting the correct file paths internally.
Place the PH script in a root directory as serveJAD.php. Place your JAR and JAD files in [...]]]></description>
			<content:encoded><![CDATA[<p>Some handy code to dynamtically serve JAD files for OTA installation. The below script sets the appropriate headers types, also tidies up the JAD file removing stray characters which can cause issues and setting the correct file paths internally.</p>
<p>Place the PH script in a root directory as serveJAD.php. Place your JAR and JAD files in a subdirectory /J2ME</p>
<p>Call the script by serveJAD.php?format=J2ME&#038;file={jad minus extension} or you can use the Apache rewrite below and call as /J2ME/file.jad</p>
<p>ie</p>
<p>serveJAD.php?format=J2ME&#038;file=game</p>
<p>or with Apache rewrite </p>
<p>/J2ME/game.jad</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?</span>
	<span style="color: #0000ff;">$format</span>   = <span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;format&quot;</span><span style="color: #66cc66;">&#93;</span>;
	<span style="color: #0000ff;">$file</span>     = <span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;file&quot;</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #ff0000;">&quot;.jad&quot;</span>;
    <span style="color: #000066;">header</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Cache-Control: no-cache, must-revalidate,no-transform&quot;</span> <span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000066;">header</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Pragma: no-cache&quot;</span> <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000066;">header</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-type: text/vnd.sun.j2me.app-descriptor&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000066;">header</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-Disposition: attachment; filename=&quot;</span>.<span style="color: #0000ff;">$file</span>.<span style="color: #ff0000;">&quot;;&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$jad</span> = <span style="color: #000066;">file_get_contents</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;./&quot;</span>.<span style="color: #0000ff;">$format</span>.<span style="color: #ff0000;">&quot;/&quot;</span>.<span style="color: #0000ff;">$file</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$lines</span> = <span style="color: #000066;">explode</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>,<span style="color: #0000ff;">$jad</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$final</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
	<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lines</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$line</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$line</span> = <span style="color: #000066;">trim</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$line</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">strlen</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$line</span><span style="color: #66cc66;">&#41;</span>&gt;<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #0000ff;">$keypair</span> = <span style="color: #000066;">explode</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;: &quot;</span>,<span style="color: #0000ff;">$line</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$keypair</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>==<span style="color: #ff0000;">'MIDlet-Jar-URL'</span> || <span style="color: #000066;">stristr</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$keypair</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>,<span style="color: #ff0000;">&quot;RIM-COD-URL&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				<span style="color: #0000ff;">$url</span> = <span style="color: #000066;">trim</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$keypair</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #000066;">stristr</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$url</span>,<span style="color: #ff0000;">&quot;http:&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
					<span style="color: #0000ff;">$keypair</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;http://&quot;</span>.<span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;HTTP_HOST&quot;</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #ff0000;">&quot;/$format/&quot;</span>.<span style="color: #0000ff;">$url</span>;
				<span style="color: #66cc66;">&#125;</span>
			<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$keypair</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>==<span style="color: #ff0000;">'MIDlet-Jar-Size'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				<span style="color: #0000ff;">$keypair</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span> =  <span style="color: #000066;">filesize</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;./&quot;</span>.<span style="color: #0000ff;">$format</span>.<span style="color: #ff0000;">&quot;/&quot;</span>.<span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;file&quot;</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #ff0000;">&quot;.jar&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #0000ff;">$line</span> = <span style="color: #000066;">join</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;: &quot;</span>,<span style="color: #0000ff;">$keypair</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0000ff;">$l</span> = <span style="color: #000066;">trim</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$line</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #000066;">empty</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$final</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #0000ff;">$final</span>.=<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
			<span style="color: #0000ff;">$final</span>.=<span style="color: #0000ff;">$l</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #000066;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$final</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><code><br />
    RewriteEngine On<br />
    RewriteRule /J2ME/(.*)\.jad /serveJAD.php?format=J2ME&#038;file=$1<br />
</code></p>
<p>You can also use this to build automatic index pages, using this as dir.php?format=J2ME</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #0000ff;">$format</span>   = <span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;format&quot;</span><span style="color: #66cc66;">&#93;</span>;
	<span style="color: #0000ff;">$scanthis</span> = <span style="color: #ff0000;">&quot;./&quot;</span>.<span style="color: #0000ff;">$format</span>;
 	<span style="color: #0000ff;">$scanlisting</span> = scandir<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$scanthis</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #0000ff;">$dirlisting</span> = <span style="color: #000066;">array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$scanlisting</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$key</span> =&gt; <span style="color: #0000ff;">$value</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">stristr</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$value</span>,<span style="color: #ff0000;">&quot;jad&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #0000ff;">$name</span> = <span style="color: #000066;">explode</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span>,<span style="color: #0000ff;">$value</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0000ff;">$dirlisting</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$name</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #000066;">ksort</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$dirlisting</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #ff0000;">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> <span style="color: #ff0000;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span>&gt;
&lt;html xmlns=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;
&lt;head&gt;
&lt;link href=<span style="color: #ff0000;">&quot;apps.css&quot;</span> rel=<span style="color: #ff0000;">&quot;stylesheet&quot;</span> type=<span style="color: #ff0000;">&quot;text/css&quot;</span> /&gt;
&lt;meta http-equiv=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> content=<span style="color: #ff0000;">&quot;text/html; charset=iso-8859-1&quot;</span> /&gt;
&lt;title&gt;Application listing&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;p&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$dirlisting</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$name</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;a href=<span style="color: #ff0000;">&quot;/&lt;?php print($format);?&gt;/&lt;?php print($name);?&gt;.jad&quot;</span>&gt;&lt;?php <span style="color: #000066;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">&#41;</span>;?&gt;&lt;/a&gt;&lt;br /&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #66cc66;">&#125;</span>
?&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>


<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F62&amp;title=Serve+JAD+files+OTA+with+PHP" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F62&amp;title=Serve+JAD+files+OTA+with+PHP" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F62&amp;title=Serve+JAD+files+OTA+with+PHP" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F62&amp;title=Serve+JAD+files+OTA+with+PHP" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F62&amp;title=Serve+JAD+files+OTA+with+PHP', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://del.icio.us/favicon.ico" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F62" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F62&amp;title=Serve+JAD+files+OTA+with+PHP" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F62&amp;title=Serve+JAD+files+OTA+with+PHP" title="Stumble it!"><img src="/icon_stumbleupon.gif" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.jatfq.com/archives/62/feed</wfw:commentRss>
		</item>
		<item>
		<title>Capturing websites to an image</title>
		<link>http://www.jatfq.com/archives/11</link>
		<comments>http://www.jatfq.com/archives/11#comments</comments>
		<pubDate>Fri, 21 Sep 2007 22:08:26 +0000</pubDate>
		<dc:creator>Sime</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.jatfq.com/archives/11</guid>
		<description><![CDATA[This is a &#8220;thinking outside the box&#8221; way to automatically snap a website and save it to a JPG.  It uses webswoon, a great little app, a little buggy here and there but it does the job.
You will need:
Webswoon
Apache + PHP ( Note: Apache MUST be running as a standalone, not as a service [...]]]></description>
			<content:encoded><![CDATA[<p>This is a &#8220;thinking outside the box&#8221; way to automatically snap a website and save it to a JPG.  It uses <a href="http://www.alcenia.com/webswoon/">webswoon</a>, a great little app, a little buggy here and there but it does the job.</p>
<p><strong>You will need:</strong><br />
Webswoon<br />
Apache + PHP ( Note: Apache MUST be running as a standalone, not as a service )<br />
A Windows Machine to run it on ( oh stop crying ) - I use an old PIII with Windows 2000 installed.</p>
<p>Right, I&#8217;m gonna assume everything is installed.  Are you asking me why Apache must be running standalone? Because webswoon is actually a wrapper for the IE ActiveX object ( or something like that ). For IE to run it need a desktop to run on with color depth and all those funky things. Services don&#8217;t have a desktop, so IE can&#8217;t run. There may be a way around it, frankly I haven&#8217;t the time to make it work.</p>
<p>Now configure webswoon:</p>
<p><code>openbrowserwindow=0<br />
thumbnailwidth=150<br />
thumbnailheight=110<br />
browserwidth=850<br />
browserheight=640<br />
waitdelay=2<br />
updatecaptures=0<br />
updatedays=60<br />
updatehours=0<br />
updatemins=0<br />
exportfolder=C:\Program Files\Apache Group\Apache2\htdocs\captures<br />
capturefilenameformat=%z.%e<br />
ignoreurl=<br />
imageformat=JPG<br />
timeoutdelay=13<br />
deletecaptures=0<br />
removeborder=1<br />
loopmode=0<br />
loopdelay=60<br />
jpegcompression=80<br />
automode=0<br />
showbrowsererror=0<br />
language=en<br />
disablejavascript=1<br />
resizecapture=1<br />
cropmethod=1<br />
keepmargins=1<br />
blankmargin=20<br />
canvawidth=1200<br />
canvaheight=6000</code></p>
<p>&#8220;exportfolder&#8221; does not really matter as we override that later. You can play with the other settings, have at them.</p>
<p>Now, we create a batch file, somewhere that Apache can get hold of it:</p>
<p><code>cd "{path to webswoon}"<br />
"{path to webswoon}\webswoon_console" -f %1 -o "{where ur captures are going}"</code></p>
<p>Fill out the curly brackets with your own paths, and save as capture.bat</p>
<p>Now the PHP file thusly:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="php"><span style="color: #000066;">error_reporting</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Use ur frickin imagination here ...</span>
<span style="color: #0000ff;">$path</span> = <span style="color: #ff0000;">&quot;C:/Program Files/WebSwoon&quot;</span>;
&nbsp;
<span style="color: #0000ff;">$url</span> = <span style="color: #0000ff;">$HTTP_GET_VARS</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;URL&quot;</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">empty</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$url</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #b1b100;">return</span>;
<span style="color: #0000ff;">$filename</span> = <span style="color: #ff0000;">&quot;/lists/&quot;</span>.getmicrotime<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot;.txt&quot;</span>;
<span style="color: #0000ff;">$file</span> = <span style="color: #000066;">fopen</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$path</span>.<span style="color: #0000ff;">$filename</span>,<span style="color: #ff0000;">&quot;w+&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000066;">fputs</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file</span>,<span style="color: #ff0000;">&quot;http://&quot;</span>.<span style="color: #0000ff;">$url</span>.<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000066;">fclose</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Add the absolute path to your batch file</span>
<span style="color: #808080; font-style: italic;">// I just coded it here a c:\</span>
<span style="color: #0000ff;">$exec</span> = <span style="color: #ff0000;">&quot;c:<span style="color: #000099; font-weight: bold;">\c</span>apture.bat $filename&quot;</span>;
<span style="color: #0000ff;">$WshShell</span> = <span style="color: #000000; font-weight: bold;">new</span> COM<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;WScript.Shell&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$WshShell</span>-&gt;<span style="color: #006600;">Run</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;$exec&quot;</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000066;">unlink</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$path</span>.<span style="color: #0000ff;">$filename</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>This allows you to pass the URL ( without HTTP in this case ) as a parameter (&#8221;URL&#8221;) but you can do this many other ways, this is just the way I do it.</p>
<p>So, PHP comes along, creates a file, named with the current time in milliseconds and sets the contents to the URL we want to capture. This file normally has to be in the webswoon directory ( I put it in the &#8220;lists&#8221; subdirectory ). We then call our batch file to launch webswoon in command line mode, which will read the list of URLs and capture them to our output directory, with a filename of {MD5 filename}.jpg</p>
<p>Another note is that the PHP exec() function doesn&#8217;t work in this instance ( at least, it didn&#8217;t when I wrote the original code ), so we use a windows shell object ( essentially use Explorer to run the batch file )</p>
<p><code>$WshShell = new COM("WScript.Shell");<br />
$WshShell->Run("$exec", 0, true);</code></p>
<p>Webswoon will sometimes get stuck under it&#8217;s own feet. It is set to timeout after 15 seconds, but some pages will screw that up. So I have a scheduled job that runs a windows version of the unix KILL command thusly:</p>
<p><code>kill -f webswoon*</code></p>
<p>It runs every so often just to tidy things up.</p>
<p>Want to see a working example of all this stuff?</p>
<p><a href="http://convert.springheadmedia.com/webshot/index.php">http://convert.springheadmedia.com/webshot/index.php</a></p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F11&amp;title=Capturing+websites+to+an+image" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F11&amp;title=Capturing+websites+to+an+image" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F11&amp;title=Capturing+websites+to+an+image" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F11&amp;title=Capturing+websites+to+an+image" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F11&amp;title=Capturing+websites+to+an+image', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://del.icio.us/favicon.ico" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F11" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F11&amp;title=Capturing+websites+to+an+image" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F11&amp;title=Capturing+websites+to+an+image" title="Stumble it!"><img src="/icon_stumbleupon.gif" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.jatfq.com/archives/11/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
