<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BIOSTALL</title>
	<atom:link href="http://biostall.com/feed" rel="self" type="application/rss+xml" />
	<link>http://biostall.com</link>
	<description>Web Development Snippets, Hints and Tips</description>
	<lastBuildDate>Tue, 30 Apr 2013 16:06:19 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Filter WordPress Search Results by One or More Post Types</title>
		<link>http://biostall.com/filter-wordpress-search-results-by-one-or-more-post-types</link>
		<comments>http://biostall.com/filter-wordpress-search-results-by-one-or-more-post-types#comments</comments>
		<pubDate>Tue, 30 Apr 2013 16:06:19 +0000</pubDate>
		<dc:creator>Steve Marks</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://biostall.com/?p=1278</guid>
		<description><![CDATA[By default, performing a search on a WordPress website will search through everything; all pages, posts, and any custom posts types that have been created. I came across a scenario earlier however where I wanted to exclude pages from the search and filter the results by multiple custom post types. To be honest I struggled [...]]]></description>
				<content:encoded><![CDATA[<p>By default, performing a search on a WordPress website will search through everything; all pages, posts, and any custom posts types that have been created. I came across a scenario earlier however where I wanted to exclude pages from the search and filter the results by multiple custom post types. </p>
<p>To be honest I struggled to find the solution immediately so wanted to explain how you can filter by one or more post types. For both of the explanations below I will explain how this can be achieved by editing the search form, or by editing the themes <em>functions.php</em> file.</p>
<p>Note: For information on creating a search form see this link:</p>
<p><a href="http://codex.wordpress.org/Function_Reference/get_search_form" target="_blank">http://codex.wordpress.org/Function_Reference/get_search_form</a></p>
<p><strong>Filter Search Results by a Single Post Type</strong></p>
<p><u>Search Form</u></p>
<pre name="code" class="html">&lt;form method="get" id="searchform" action="&lt;?php echo esc_url( home_url( '/' ) ); ?&gt;"&gt;
	&lt;input type="text" class="field" name="s" id="s"&gt;
	&lt;input type="hidden" class="field" name="post_type" id="post_type" value="movies"&gt;
	&lt;input type="submit" class="submit" name="submit" id="searchsubmit" value="&lt;?php esc_attr_e( 'Search' ); ?&gt;"&gt;
&lt;/form&gt;</pre>
<p><u>functions.php</u></p>
<pre name="code" class="php">function SearchFilter($query) 
{
	if ($query-&gt;is_search) 
	{
		$query->set('post_type', 'movies');
	}
	return $query;
}
add_filter('pre_get_posts', 'SearchFilter');</pre>
<p><strong>Filter Search Results by Multiple Post Types</strong></p>
<p><u>Search Form</u></p>
<pre name="code" class="html">&lt;form method="get" id="searchform" action="&lt;?php echo esc_url( home_url( '/' ) ); ?&gt;"&gt;
	&lt;input type="text" class="field" name="s" id="s"&gt;
	&lt;input type="hidden" class="field" name="post_type[]" id="post_type" value="movies"&gt;
	&lt;input type="hidden" class="field" name="post_type[]" id="post_type" value="photos"&gt;
	&lt;input type="submit" class="submit" name="submit" id="searchsubmit" value="&lt;?php esc_attr_e( 'Search' ); ?&gt;"&gt;
&lt;/form&gt;</pre>
<p><u>functions.php</u></p>
<pre name="code" class="php">function SearchFilter($query) 
{
	if ($query-&gt;is_search) 
	{
		$query->set('post_type', array('movies', 'photos'));
	}
	return $query;
}
add_filter('pre_get_posts', 'SearchFilter');</pre>
<p>So there we have it. By using an array we can filter the search results by two or more post types.</p>
]]></content:encoded>
			<wfw:commentRss>http://biostall.com/filter-wordpress-search-results-by-one-or-more-post-types/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Appending Data To Existing CodeIgniter Session Variable</title>
		<link>http://biostall.com/appending-data-to-existing-codeigniter-session-variable</link>
		<comments>http://biostall.com/appending-data-to-existing-codeigniter-session-variable#comments</comments>
		<pubDate>Mon, 15 Apr 2013 14:38:57 +0000</pubDate>
		<dc:creator>Steve Marks</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[sessions]]></category>

		<guid isPermaLink="false">http://biostall.com/?p=1272</guid>
		<description><![CDATA[When storing information in a session, it is likely that you may want to add additional inormation to this session at a later date. For this particular post I&#8217;ll be focusing on how to achieve this within CodeIgniter. Allow me therefore to first demonstrate how the session we will be extending may be getting initialised [...]]]></description>
				<content:encoded><![CDATA[<p>When storing information in a session, it is likely that you may want to add additional inormation to this session at a later date. For this particular post I&#8217;ll be focusing on how to achieve this within CodeIgniter. Allow me therefore to first demonstrate how the session we will be extending may be getting initialised in the first place:</p>
<pre name="code" class="php">$data = array(
	'username' =&gt; 'joebloggs',
	'name' =&gt; 'Joe Bloggs',
	'email' =&gt; 'joe@bloggs.com'
);

$this->session->set_userdata('user', $data);</pre>
<p>In the above code we are creating a session called &#8216;user&#8217;, then assigning an array to it containing the users information.</p>
<p>Now, lets imagine that at a later date we also want to add a phone number to this session. We can do this easily using the method outlined below:</p>
<pre name="code" class="php">$data = $this->session->userdata('user');

$data['telno'] = "01234 567 890";

$this->session->set_userdata('user', $data);</pre>
<p>If you can&#8217;t make out what we&#8217;re doing here, we&#8217;re assigning the existing user data to a variable called $data. We then add an extra element to the array, in our case this is the user&#8217;s telephone number, then overwrite the existing user session with the new infrmation.</p>
]]></content:encoded>
			<wfw:commentRss>http://biostall.com/appending-data-to-existing-codeigniter-session-variable/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing Error &#8220;Process exited with code 1633&#8243; When Installing SyncToy</title>
		<link>http://biostall.com/fixing-error-process-exited-with-code-1633-when-installing-synctoy</link>
		<comments>http://biostall.com/fixing-error-process-exited-with-code-1633-when-installing-synctoy#comments</comments>
		<pubDate>Tue, 09 Apr 2013 12:51:32 +0000</pubDate>
		<dc:creator>Steve Marks</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://biostall.com/?p=1269</guid>
		<description><![CDATA[SyncToy from Microsoft is a great little program to ensure that two folders are kept in sync. I personally use it to ensure local folders and networked folders are kept up to date. Whilst recently installing it on a new PC however, I came across the following error in the logs: Process exited with code [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.microsoft.com/en-gb/download/details.aspx?id=15155" target="_blank">SyncToy from Microsoft</a> is a great little program to ensure that two folders are kept in sync. I personally use it to ensure local folders and networked folders are kept up to date.</p>
<p>Whilst recently installing it on a new PC however, I came across the following error in the logs:</p>
<p><code>Process exited with code 1633</code></p>
<p><strong>The Solution</strong></p>
<p>The problem turned out to be that I had downloaded and installed the wrong version. On the downloads page there are two versions of SyncToy available; a x64 version and a x86 version.</p>
<p>After trying the other, correct package, it installed and ran immediately as expected.</p>
]]></content:encoded>
			<wfw:commentRss>http://biostall.com/fixing-error-process-exited-with-code-1633-when-installing-synctoy/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Add Swipe Functionality To jCarousel Lite</title>
		<link>http://biostall.com/how-to-add-swipe-functionality-to-jcarousel-lite</link>
		<comments>http://biostall.com/how-to-add-swipe-functionality-to-jcarousel-lite#comments</comments>
		<pubDate>Mon, 08 Apr 2013 14:34:02 +0000</pubDate>
		<dc:creator>Steve Marks</dc:creator>
				<category><![CDATA[Javascript / jQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://biostall.com/?p=1267</guid>
		<description><![CDATA[I&#8217;ve been using the jCarousel Lite plugin from Ganeshji Marwaha for many years now and find it incredibly easy to work with. Due to it&#8217;s simplicity It&#8217;s also proved easy to modify when I&#8217;ve wanted to add additional functionality. I was recently working on a site that would be used on a mobile or tablet [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been using the jCarousel Lite plugin from <a href="http://www.gmarwaha.com/jquery/jcarousellite/" target="_blank">Ganeshji Marwaha</a> for many years now and find it incredibly easy to work with. Due to it&#8217;s simplicity It&#8217;s also proved easy to modify when I&#8217;ve wanted to add additional functionality.</p>
<p>I was recently working on a site that would be used on a mobile or tablet device, and therefore required the carousels be controlled through swipe motions and the users using their fingers to control the direction of the carousel. The current plugin I was using doesn&#8217;t come with this functionality included (probably due to it&#8217;s age) so I needed to look elsewhere.</p>
<p>Luckily for me it turned out that a chap called <a href="http://www.karlswedberg.com/" target="_blank">Karl Swedberg</a> has continued, and still maintains, his own version of the <a href="https://github.com/kswedberg/jquery-carousel-lite" target="_blank">jCarousel Lite plugin</a>. The &#8216;swipe&#8217; option is activated by default so the mobile functionality works straight out of the box.</p>
<p>The other great thing is, that because this improved plugin simply extends the original, I can simply go back through my old sites containing carousels and drop it in over the top without having to change any code.</p>
]]></content:encoded>
			<wfw:commentRss>http://biostall.com/how-to-add-swipe-functionality-to-jcarousel-lite/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prevent Slides Fading Out Between Transitions in jQuery Cycle Plugin</title>
		<link>http://biostall.com/prevent-slides-fading-out-between-transitions-in-jquery-cycle-plugin</link>
		<comments>http://biostall.com/prevent-slides-fading-out-between-transitions-in-jquery-cycle-plugin#comments</comments>
		<pubDate>Thu, 04 Apr 2013 18:32:13 +0000</pubDate>
		<dc:creator>Steve Marks</dc:creator>
				<category><![CDATA[Javascript / jQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://biostall.com/?p=1261</guid>
		<description><![CDATA[The jQuery Cycle Plugin from Malsup is a plugin that I use on a regular basis. It&#8217;s easy to add to a site, customisable, and the documentation and examples on the website are excellent. One thing that&#8217;s always gnarked me a little about the plugin however is how the slides always fade out before the [...]]]></description>
				<content:encoded><![CDATA[<p>The <a href="http://www.malsup.com/jquery/cycle/" target="_blank">jQuery Cycle Plugin from Malsup</a> is a plugin that I use on a regular basis. It&#8217;s easy to add to a site, customisable, and the documentation and examples on the website are excellent.</p>
<p>One thing that&#8217;s always gnarked me a little about the plugin however is how the slides always fade out before the next one fades in. This results in seeing a glimpse of the background colour for a split second. I couldn&#8217;t see an option in the available parameters to disable this, so set about looking for the responsible code in the plugin file itself.</p>
<p><strong>The Solution</strong></p>
<p>The plugin file itself is quite large so it took a while to find the culprit code. The change required however is tiny, one character to be precise. You simply need to do a search and amend the following line of code (for me it was line 997) from:</p>
<pre name="code" class="javascript">opts.animOut = { opacity: 0 };</pre>
<p>To:</p>
<pre name="code" class="javascript">opts.animOut = { opacity: 1 };</pre>
<p>In making the change above, the slides no longer faded out, and the next slide simply faded in over the top of the previous one.</p>
]]></content:encoded>
			<wfw:commentRss>http://biostall.com/prevent-slides-fading-out-between-transitions-in-jquery-cycle-plugin/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML5 Video Playing Sound But No Visual</title>
		<link>http://biostall.com/html5-video-playing-sound-but-no-visual</link>
		<comments>http://biostall.com/html5-video-playing-sound-but-no-visual#comments</comments>
		<pubDate>Sat, 30 Mar 2013 21:39:33 +0000</pubDate>
		<dc:creator>Steve Marks</dc:creator>
				<category><![CDATA[(X)HTML / CSS]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://biostall.com/?p=1257</guid>
		<description><![CDATA[When I first heard murmerings of HTML5 a few years back, the ability to add video through use of a simple &#60;video&#62; tag was one of the first new features I remember being discussed. Up until last week, I still hadn&#8217;t had the opportunity to have a play with this functionality. My chance came on [...]]]></description>
				<content:encoded><![CDATA[<p>When I first heard murmerings of HTML5 a few years back, the ability to add video through use of a simple &lt;video&gt; tag was one of the first new features I remember being discussed. Up until last week, I still hadn&#8217;t had the opportunity to have a play with this functionality.</p>
<p>My chance came on a site that wanted to use video heavily in lightboxes to demonstrate a new product they were releasing. I did some research into the different video formats supported across devicces and browsers, and set to work. I actually ended up using <a href="http://videojs.com/" target="_blank">Video.js</a> due to its ability to provide a Flash fallback and to incorporate different skins. I got the video player code added in a few minutes and was ready to hit the &#8216;Play&#8217; button on the website.</p>
<p>In FireFox the lightbox opened and the video played as expected. In Safari and Chrome however, the audio of the video could be heard but without the visual. I tried different video formats, different video players, different everything, but the two browsers would not behave as expected and simply just kept playing the sound.</p>
<p><strong>The Solution</strong></p>
<p>I mentioned that the videos were being shown in a lightbox. As a result I&#8217;d gone to some effort to hide and show the lightbox layer when the &#8216;Play&#8217; button was clicked. What I didn&#8217;t realise however was that I&#8217;d hidden the actual &lt;video&gt; tag by doing something like so:</p>
<pre name="code" class="html">&lt;video id="lightbox-video-player" style="display:none" class="video-js vjs-default-skin" controls preload="auto" width="1000" height="563" data-setup="{}"&gt;
	&lt;source src="/my-video.mp4" type='video/mp4'&gt;
	&lt;source src="/my-video.ogg" type='video/ogg'&gt;
&lt;/video&gt;</pre>
<p>Notice that I&#8217;d put a &#8216;display:none&#8217; on the video? This was the reason for only hearing sound on Chrome and Safari and, after removing this, the video played as expected.</p>
]]></content:encoded>
			<wfw:commentRss>http://biostall.com/html5-video-playing-sound-but-no-visual/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating The HTML &lt;title&gt; Tag With JavaScript</title>
		<link>http://biostall.com/updating-the-html-tag-with-javascript</link>
		<comments>http://biostall.com/updating-the-html-tag-with-javascript#comments</comments>
		<pubDate>Tue, 26 Mar 2013 07:19:51 +0000</pubDate>
		<dc:creator>Steve Marks</dc:creator>
				<category><![CDATA[(X)HTML / CSS]]></category>
		<category><![CDATA[Javascript / jQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://biostall.com/?p=1252</guid>
		<description><![CDATA[Sometimes we might not know the full title of a HTML page when the page first loads, meaning that we will need to set it dynamically. I found myself in this scenario recently and needed to set the title using JavaScript. I couldn&#8217;t believe how easy it was to do and wanted to share the [...]]]></description>
				<content:encoded><![CDATA[<p>Sometimes we might not know the full title of a HTML page when the page first loads, meaning that we will need to set it dynamically. I found myself in this scenario recently and needed to set the title using JavaScript. I couldn&#8217;t believe how easy it was to do and wanted to share the result so others can do the same thing:</p>
<pre name="code" class="javascript">document.title = 'This is my new title';</pre>
<p>Yup, that&#8217;s it! I told you it was easy.</p>
<p><strong>Note:</strong> Bear in mind that search engines don&#8217;t execute JavaScript and therefore won&#8217;t take your updated title into account. Just be aware of this if you&#8217;re wary of the pages impact in serch engine rankings.</p>
]]></content:encoded>
			<wfw:commentRss>http://biostall.com/updating-the-html-tag-with-javascript/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Returning 404 Page When Submitting Custom Form</title>
		<link>http://biostall.com/wordpress-returning-404-page-when-submitting-custom-form</link>
		<comments>http://biostall.com/wordpress-returning-404-page-when-submitting-custom-form#comments</comments>
		<pubDate>Mon, 25 Mar 2013 14:17:19 +0000</pubDate>
		<dc:creator>Steve Marks</dc:creator>
				<category><![CDATA[(X)HTML / CSS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://biostall.com/?p=1250</guid>
		<description><![CDATA[There are lots of plugins available for WordPress that allow you to quickly and easily embed forms within a website. Sometimes however, you may need to build a standard form that submits the same as a non-WordPress site. I needed to do exactly this today. I built the form&#8217;s HTML, made it submit to itself [...]]]></description>
				<content:encoded><![CDATA[<p>There are lots of plugins available for WordPress that allow you to quickly and easily embed forms within a website. Sometimes however, you may need to build a standard form that submits the same as a non-WordPress site.</p>
<p>I needed to do exactly this today. I built the form&#8217;s HTML, made it submit to itself (ie. the same URL) and coded some PHP to process the form. When the form was submitted however, it just went a 404 page straight away. </p>
<p>I knew the page existed because the form was posting to the same URL, and I knew it was OK to POST data from a form, so what was the problem?</p>
<p><strong>The Solution</strong></p>
<p>In summary, WordPress has a list of reserved words for POST variables that can&#8217;t be used when building a bespoke form. In my scenario one of the textboxes had the name of &#8216;<em>name</em>&#8216;, which turned out to be one of these reserved words.</p>
<p>I don&#8217;t have a definitive list of these reserved words, however I did find a <a href="http://takien.com/1050/wordpress-reserved-global-variables-you-should-avoid-define-a-variable-using-these-name.php" target="_blank">full list here</a>.</p>
<p>Once I used a different name for the text field in question, my form then began to submit as expected.</p>
]]></content:encoded>
			<wfw:commentRss>http://biostall.com/wordpress-returning-404-page-when-submitting-custom-form/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why WordPress NextGEN Gallery or Album Pages May Return 404 Pages</title>
		<link>http://biostall.com/wordpress-nextgen-gallery-or-album-pages-return-404-pages</link>
		<comments>http://biostall.com/wordpress-nextgen-gallery-or-album-pages-return-404-pages#comments</comments>
		<pubDate>Mon, 25 Mar 2013 09:07:13 +0000</pubDate>
		<dc:creator>Steve Marks</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://biostall.com/?p=1245</guid>
		<description><![CDATA[Whilst recently implementing a NextGEN photo gallery plugin into a WordPress site, I came across a problem whereby pages that should have been displaying galleries or albums, were instead showing a 404 page. I was stuck on this problem for literally 2 hours and, after searching on forum after forum, could not find a viable [...]]]></description>
				<content:encoded><![CDATA[<p>Whilst recently implementing a NextGEN photo gallery plugin into a WordPress site, I came across a problem whereby pages that should have been displaying galleries or albums, were instead showing a 404 page.</p>
<p>I was stuck on this problem for literally 2 hours and, after searching on forum after forum, could not find a viable solution anywhere.</p>
<p>What was the cause? Well, to be fair it wasn&#8217;t the fault of the NextGEN Gallery. It was indeed my coding that had broken the photo gallery. I had setup a custom post type called &#8216;gallery&#8217; that was conflicting with the plugin. Turns out that the plugin uses the same post type name, and therefore was causing it to fail.</p>
<p>After changing my custom post type name in my themes <em>functions.php</em> file, the photo gallery began to work as expected. It would be great if the plugin detected a conflicting custom post type and warned developers about this. I&#8217;ll put it to the plugin authors and hopefully it will get added as a feature soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://biostall.com/wordpress-nextgen-gallery-or-album-pages-return-404-pages/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP&#8217;s ZipArchive Class Not Creating Zip File (And No Errors)</title>
		<link>http://biostall.com/php-ziparchive-class-not-creating-zip-file-and-no-errors</link>
		<comments>http://biostall.com/php-ziparchive-class-not-creating-zip-file-and-no-errors#comments</comments>
		<pubDate>Fri, 22 Mar 2013 19:28:01 +0000</pubDate>
		<dc:creator>Steve Marks</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[zip]]></category>

		<guid isPermaLink="false">http://biostall.com/?p=1242</guid>
		<description><![CDATA[The ZipArchive Class provides a quick and easy way to create, or extract, Zip files using PHP. I did face a problem recently though when trying to build a zip file, and it took me a while to figure out the answer. I would open a new Zip reference, add some files, and then close [...]]]></description>
				<content:encoded><![CDATA[<p>The <a href="http://www.php.net/manual/en/class.ziparchive.php" target="_blank">ZipArchive Class</a> provides a quick and easy way to create, or extract, Zip files using PHP.</p>
<p>I did face a problem recently though when trying to build a zip file, and it took me a while to figure out the answer. I would open a new Zip reference, add some files, and then close the zip immediately after. Oddly enough however there was no zip actually created and, even weirder, no errors informing me something had gone wrong with the build.</p>
<p>Let&#8217;s take a quick look at some code that builds a zip. Afterwards we&#8217;ll analyse what&#8217;s wrong with the code, why it won&#8217;t work, and how we can easily fix it:</p>
<pre name="code" class="php">// Initiate a new instance of ZipArchive
$zip = new ZipArchive();

// Open a new zip file
$res = $zip->open("myZip.zip", ZipArchive::CREATE);

// Add a file to the zip file
$zip->addFile("/path/to/file/myPhoto1.jpg", "newPhoto1.jpg");

// Add a file to the zip file
$zip->addFile("/path/to/file/myPhoto2.jpg44", "newPhoto2.jpg");

// Add a file to the zip file
$zip->addFile("/path/to/file/myPhoto3.jpg", "newPhoto3.jpg");

// Close the zip file.
// At this point it should be created
$zip->close();</pre>
<p>Now, running the above code will result in nothing at all. No zip file, or no errors. Just a completed script that apparently has done everything it was meant to do.</p>
<p><strong>The Solution</strong></p>
<p>In the code above can you tell what&#8217;s wrong? No, it&#8217;s not me making a typo. The second image we&#8217;re adding isn&#8217;t a valid image and doesn&#8217;t exist at all. As a result we&#8217;re not left with a zip file, but a sense of confusion which, for me at least, lasted a couple of hours.</p>
<p>To fix the problem we have one of two options:</p>
<p>1. Fix the path to the broken image,</p>
<p>or</p>
<p>2. Do a check that the file exists before trying to add it. This approach will involce amending the code to read something like so:</p>
<pre name="code" class="php">// Initiate a new instance of ZipArchive
$zip = new ZipArchive();

// Open a new zip file
$res = $zip->open("myZip.zip", ZipArchive::CREATE);

// Add a file to the zip file
if (file_exists("/path/to/file/myPhoto1.jpg"))
{
	$zip->addFile("/path/to/file/myPhoto1.jpg", "newPhoto1.jpg");
}

// Add a file to the zip file
if (file_exists("/path/to/file/myPhoto2.jpg44"))
{
	$zip->addFile("/path/to/file/myPhoto2.jpg44", "newPhoto2.jpg");
}

// Add a file to the zip file
if (file_exists("/path/to/file/myPhoto3.jpg"))
{
	$zip->addFile("/path/to/file/myPhoto3.jpg", "newPhoto3.jpg");
}

// Close the zip file.
// At this point it should be created
$zip->close();</pre>
<p>I personally went for the second option and after making the changes above, I was presented with the zip that I expected.</p>
]]></content:encoded>
			<wfw:commentRss>http://biostall.com/php-ziparchive-class-not-creating-zip-file-and-no-errors/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  biostall.com/feed ) in 0.38647 seconds, on May 23rd, 2013 at 4:58 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on May 23rd, 2013 at 5:58 pm UTC -->
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- Quick Cache Is Fully Functional :-) ... A Quick Cache file was just served for (  biostall.com/feed ) in 0.00101 seconds, on May 23rd, 2013 at 5:21 pm UTC. -->