<?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>Cagintranet Web Design &#187; jQuery</title>
	<atom:link href="http://www.cagintranet.com/cat/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cagintranet.com</link>
	<description>Pittsburgh Web Design Â» Cagintranet Web Design - Web Designer, Developer, Graphic Artist and Web 2.0 Guru</description>
	<lastBuildDate>Thu, 25 Mar 2010 10:32:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Tutorial: How to Implement Uploadify into an Application</title>
		<link>http://www.cagintranet.com/archive/how-to-implement-uploadify-into-an-application/</link>
		<comments>http://www.cagintranet.com/archive/how-to-implement-uploadify-into-an-application/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 10:00:32 +0000</pubDate>
		<dc:creator>Chris Cagle</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.cagintranet.com/?p=522</guid>
		<description><![CDATA[<a href="http://www.cagintranet.com/archive/how-to-implement-uploadify-into-an-application/"><img align="left" hspace="5" width="250" src="http://www.cagintranet.com/design/wp-content/uploads/2009/10/screenshot1.jpg" class="alignleft wp-post-image tfe" alt="How to Implement Uploadify into an Application" title="" /></a>Last week I showed how to implement Jcrop into an application. In this tutorial &#8211; which also pulls from my experiences developing GetSimple &#8211; I implement the jQuery plugin Uploadify. In this tutorial, we create a simple file upload script that also displays an unordered list of the files in the upload directory. The list [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.cagintranet.com/design/wp-content/uploads/2009/10/screenshot1.jpg" alt="How to Implement Uploadify into an Application" /></p>
<p>Last week I showed <a href="http://www.cagintranet.com/archive/how-to-use-jcrop-from-within-an-application/">how to implement Jcrop into an application</a>. In this tutorial &#8211; which also pulls from my experiences developing <a href="http://get-simple.info/">GetSimple</a> &#8211; I implement the jQuery plugin <a href="http://www.uploadify.com/">Uploadify</a>.</p>
<p>In this tutorial, we create a simple file upload script that also displays an unordered list of the files in the upload directory. The list of files refreshes via an ajax call every time Uploadify processes a queue.</p>
<h3>Demo</h3>
<p><a href="/code/uploadify-app/upload.php">View the demo</a> or <a href="/code/uploadify-app/uploadify-demo.zip">download the files</a></p>
<h3>The Basic HTML</h3>
<pre><code class="html">&lt;h2>Uploadify Application Demo &lt;span id="loader">&lt;img src="img/loading.gif" alt="Loading..." />&lt;/span>&lt;/h2>
&lt;div id="sidebar">
	&lt;!-- form to be replaced by uploadify -->
	&lt;form id="mainftp" action="upload.php" method="post" enctype="multipart/form-data">
		&lt;p>&lt;input type="file" name="file" id="file" />&lt;/p>
		&lt;p>&lt;input type="submit" name="submit" value="Upload" />&lt;/p>
	&lt;/form>
&lt;/div>

&lt;!-- whole div to be refreshed once uploadify is finished -->
&lt;div id="allfiles" >
	&lt;?php
		//list all files via function file included up top
		$handle = @opendir($src_folder) or die("Unable to open $src_folder");
		ListDir($handle,$src_folder);
	?>
&lt;/div></code></pre>
<h3>The PHP</h3>
<pre><code class="php">//folder where the files are stored at
//you may need to chmod this folder to 775 or 777 for it to work
$src_folder = 'files/';

//file that includes the function to list all files in ul
include("inc/file_list.php");

//if javascript is disabled, the ftp will still work
if (isset($_FILES["file"])) {
	if ($_FILES["file"]["error"] > 0) {
	  $error = 'Error Uploading!';
	} else {
    $count = '1';
    $file_loc = $path . $_FILES["file"]["name"];
    $base = $_FILES["file"]["name"];
    while ( file_exists($file_loc) ) {
		$file_loc = $path . $count.'-'. $_FILES["file"]["name"];
		$base = $count.'-'. $_FILES["file"]["name"];
		$count++;
	}
    move_uploaded_file($_FILES["file"]["tmp_name"], $file_loc);
	}
}</code></pre>
<h3>The jQuery</h3>
<pre><code class="javascript">$('#mainftp').uploadify({
	'uploader' : 'js/uploadify/uploadify.swf',
	'script' : 'js/uploadify/uploadify.php',
	'multi' : true,
	'auto' : true,
	'height' : '32',
	'width' : '250',
	'buttonImg' : 'img/browse.png',
	'cancelImg' : 'img/cancel.png',
	'folder' : 'files/',
	onProgress: function() {
		$('#loader').show();
	},
	onAllComplete: function() {
		$('#loader').hide();
		$('#allfiles').load(location.href+" #allfiles>*","");
	}
});</code></pre>
<p>Notes about this javascript:</p>
<ul>
<li>Uploadify was unzipped directly from the <a href="http://www.uploadify.com/download/">download on their site</a>. To upgrade, simply replace the <em>js/uploadify/</em> folder with the newer version.</li>
<li><b>height</b> and <b>width</b> are for the respective dimentions of your custom button image &#8211; the demo&#8217;s being in <em>img/browse.png</em></li>
<li><b>folder</b> is the location where the files will be uploaded to. This is also the folder that should be listed on line #3 of the PHP code above in the <em>$src_folder</em> variable.</li>
<li><b>$(&#8216;#loader&#8217;).show();</b> and <b>$(&#8216;#loader&#8217;).hide();</b> start and stop the loading gif that many applications use now to show that something is being uploaded/processed.</li>
<li><b>$(&#8216;#allfiles&#8217;).load(location.href+&#8221; #allfiles>*&#8221;,&#8221;");</b> &#8211; replaces the whole div with the id of <em>allfiles</em> with and updated listing with the newly uploaded files in it</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cagintranet.com/archive/how-to-implement-uploadify-into-an-application/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>Tutorial: How to Implement Jcrop into an Application</title>
		<link>http://www.cagintranet.com/archive/how-to-use-jcrop-from-within-an-application/</link>
		<comments>http://www.cagintranet.com/archive/how-to-use-jcrop-from-within-an-application/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 20:17:19 +0000</pubDate>
		<dc:creator>Chris Cagle</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.cagintranet.com/?p=507</guid>
		<description><![CDATA[<a href="http://www.cagintranet.com/archive/how-to-use-jcrop-from-within-an-application/"><img align="left" hspace="5" width="250" src="http://www.cagintranet.com/design/wp-content/uploads/2009/10/screenshot.jpg " class="alignleft wp-post-image tfe" alt="How to use Jcrop from within an Application - Tutorial" title="" /></a>When creating the &#8216;image control panel&#8217; for the latest version of GetSimple, I decided to integrate the wonderful Jcrop jQuery plugin into it. Amazingly, there are very few tutorials online that show the full extent of how to use Jcrop in real world situations. The only one I found that was of use was TalkInCode&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.cagintranet.com/design/wp-content/uploads/2009/10/screenshot.jpg " alt="How to use Jcrop from within an Application - Tutorial" /></p>
<p>When creating the &#8216;image control panel&#8217; for the latest version of <a href="http://get-simple.info/">GetSimple</a>, I decided to integrate the wonderful <a href="http://deepliquid.com/content/Jcrop.html">Jcrop jQuery plugin</a> into it. Amazingly, there are very few tutorials online that show the full extent of how to use Jcrop in real world situations. The only one I found that was of use was <a href="http://www.talkincode.com/jcrop-extension-implementation-in-php-932.html">TalkInCode&#8217;s tutorial</a>. I did start out using that example&#8217;s ImageManipulation class, but changed it slightly so that after submission, you are brought back to the original page instead of being shown the thumbnail.</p>
<h3>Demo &amp; Features</h3>
<p><a href="http://www.cagintranet.com/code/jcrop-app/image.php?i=pittsburgh.jpg">View the Demo</a> or <a href="http://www.cagintranet.com/code/jcrop-app/jcrop-demo.zip">download the files</a>.</p>
<p>Some of the more unique features of this demo are:</p>
<ul>
<li>The aspectRatio changes to 1:1 when ctrl-Q or command-Q is pressed</li>
<li>The dimensions of the selected area are shown in an interesting way</li>
<li>Stats on the thumbnail and the current image are displayed</li>
</ul>
<h3>The Basic HTML</h3>
<p><em>The demo/download has some extra code for displaying the image stats &amp; linking of the css, js and class files.</em></p>
<pre><code class="html">&lt;!-- image for Jcrop -->
&lt;img src="&lt;?php echo $src_folder . $src; ?>" id="cropbox" />

&lt;!-- selection dimentions -->
&lt;div id="handw" class="toggle" >Selection Dimentions&lt;br />&lt;span id="picw">&lt;/span> x &lt;span id="pich">&lt;/span>&lt;/div>

&lt;!-- form that Jcrop fills in -->
&lt;form id="jcropform" action="image.php?i=&lt;?php echo $src; ?>" method="post" onsubmit="return checkCoords();">
  &lt;input type="hidden" id="x" name="x" />
  &lt;input type="hidden" id="y" name="y" />
  &lt;input type="hidden" id="w" name="w" />
  &lt;input type="hidden" id="h" name="h" />
  &lt;input type="submit" class="submit" value="Create Thumbnail" />
  &nbsp; &lt;span class="small" >&lt;em>ctrl-Q&lt;/em> or &lt;em>command-Q&lt;/em> for square&lt;/span>
&lt;/form></code></pre>
<h3>The PHP</h3>
<pre><code class="php">//the name of the passed image
//example would be:   http://myapplication.com/image.php?i=photo.jpg
$src = $_GET['i'];

//folder where the images are
$src_folder = 'images/';

//folder where the thumbnails will be saved to
//you may need to chmod 775 or 777 this folder
$thumb_folder = 'images/thumbnails/'; 

if ($_SERVER['REQUEST_METHOD'] == 'POST'){

	require('inc/imagemanipulation.php');

	$objImage = new ImageManipulation($src_folder . $src);
	if ( $objImage->imageok ) {
		$objImage->setCrop($_POST['x'], $_POST['y'], $_POST['w'], $_POST['h']);
		$objImage->save($thumb_folder . 'thumbnail.' .$src);
	} else {
		echo 'Error!';
	}
}</code></pre>
<h3>The jQuery</h3>
<pre><code class="javascript">function updateCoords(c) {
	$('#handw').show();
  $('#x').val(c.x);
  $('#y').val(c.y);
  $('#w').val(c.w);
  $('#h').val(c.h);
  $('#pich').html(c.h);
  $('#picw').html(c.w);
};

function checkCoords()
{
  if (parseInt($('#x').val())) return true;
  alert('Please select a crop region then press submit.');
  return false;
};

jQuery(document).ready(function() { 

	$(window).load(function(){
	var api = $.Jcrop('#cropbox',{
    onChange: updateCoords,
    onSelect: updateCoords,
    boxWidth: 500,
    boxHeight: 500
  });
  var isCtrl = false;
	$(document).keyup(function (e) {
		api.setOptions({ aspectRatio: 0 });
		api.focus();
		if(e.which == 17) isCtrl=false;
	}).keydown(function (e) {
		if(e.which == 17) isCtrl=true;
		if(e.which == 81 &#038;&#038; isCtrl == true) {
			api.setOptions({ aspectRatio: 1 });
			api.focus();
		}
	});
});

});
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cagintranet.com/archive/how-to-use-jcrop-from-within-an-application/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
