<?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>aseba &#187; Tecnico</title>
	<atom:link href="http://blog.aseba.com.ar/category/tecnico/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.aseba.com.ar</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 13 Sep 2011 13:55:50 +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>Buscar archivo debajo del cursor en VIM</title>
		<link>http://blog.aseba.com.ar/2011/03/buscar-archivo-debajo-del-cursor-en-vim/</link>
		<comments>http://blog.aseba.com.ar/2011/03/buscar-archivo-debajo-del-cursor-en-vim/#comments</comments>
		<pubDate>Sat, 26 Mar 2011 21:04:09 +0000</pubDate>
		<dc:creator>aseba</dc:creator>
				<category><![CDATA[Tecnico]]></category>
		<category><![CDATA[archivos]]></category>
		<category><![CDATA[buscar]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[vimrc]]></category>

		<guid isPermaLink="false">http://blog.aseba.com.ar/?p=690</guid>
		<description><![CDATA[Trabajando con una aplicación que usa templates, me encontré muchas veces viendo que cierto script abre después cierto template, si quiero ver ese archivo, tengo que buscarlo. Lo mismo si tengo imports.. Buscando en el wiki de vim encontre un script que sirve para encontrar archivos dentro del directorio donde estas parado (cd).. Yo lo [...]]]></description>
			<content:encoded><![CDATA[<p>Trabajando con una aplicación que usa templates, me encontré muchas veces viendo que cierto script abre después cierto template, si quiero ver ese archivo, tengo que buscarlo. Lo mismo si tengo imports..</p>
<p>Buscando <a target="_blank" href="http://vim.wikia.com/">en el wiki de vim</a> encontre un <a target="_blank" href="http://vim.wikia.com/wiki/Find_files_in_subdirectories">script</a> que sirve para encontrar archivos dentro del directorio donde estas parado (cd).. Yo lo modifiqué un poco y quedó asi:</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">&quot;Function for finding files</span>
<span style="color: #adadad; font-style: italic;">&quot; Find file in current directory and edit it.</span>
<span style="color: #804040;">function</span><span style="color: #000000;">!</span> Find<span style="color: #000000;">&#40;</span>name<span style="color: #000000;">&#41;</span>
  <span style="color: #804040;">let</span> l<span style="color: #000000;">:</span>list=<span style="color: #25BB4D;">system</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;find . -name '&quot;</span><span style="color: #000000;">.</span>a<span style="color: #000000;">:</span>name<span style="color: #000000;">.</span><span style="color: #C5A22D;">&quot;*[htm|html|php]' | grep -v .svn | perl -ne 'print <span style="">\&quot;</span>$.<span style="">\\</span>t$_<span style="">\&quot;</span>'&quot;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #804040;">let</span> l<span style="color: #000000;">:</span>num=<span style="color: #25BB4D;">strlen</span><span style="color: #000000;">&#40;</span><span style="color: #25BB4D;">substitute</span><span style="color: #000000;">&#40;</span>l<span style="color: #000000;">:</span>list, <span style="color: #C5A22D;">&quot;[^<span style="">\n</span>]&quot;</span>, <span style="color: #C5A22D;">&quot;&quot;</span>, <span style="color: #C5A22D;">&quot;g&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #804040;">if</span> l<span style="color: #000000;">:</span>num <span style="color: #000000;">&lt;</span> <span style="color: #000000; font-weight:bold;">1</span>
    <span style="color: #804040;">echo</span> <span style="color: #C5A22D;">&quot;'&quot;</span><span style="color: #000000;">.</span>a<span style="color: #000000;">:</span>name<span style="color: #000000;">.</span><span style="color: #C5A22D;">&quot;' not found&quot;</span>
    <span style="color: #804040;">return</span>
  <span style="color: #804040;">endif</span>
  <span style="color: #804040;">if</span> l<span style="color: #000000;">:</span>num <span style="color: #000000;">!</span>= <span style="color: #000000; font-weight:bold;">1</span>
    <span style="color: #804040;">echo</span> l<span style="color: #000000;">:</span>list
    <span style="color: #804040;">let</span> l<span style="color: #000000;">:</span><span style="color: #25BB4D;">input</span>=<span style="color: #25BB4D;">input</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;Which ? (CR=nothing)<span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #804040;">if</span> <span style="color: #25BB4D;">strlen</span><span style="color: #000000;">&#40;</span>l<span style="color: #000000;">:</span><span style="color: #25BB4D;">input</span><span style="color: #000000;">&#41;</span>==<span style="color: #000000; font-weight:bold;">0</span>
      <span style="color: #804040;">return</span>
    <span style="color: #804040;">endif</span>
    <span style="color: #804040;">if</span> <span style="color: #25BB4D;">strlen</span><span style="color: #000000;">&#40;</span><span style="color: #25BB4D;">substitute</span><span style="color: #000000;">&#40;</span>l<span style="color: #000000;">:</span><span style="color: #25BB4D;">input</span>, <span style="color: #C5A22D;">&quot;[0-9]&quot;</span>, <span style="color: #C5A22D;">&quot;&quot;</span>, <span style="color: #C5A22D;">&quot;g&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&gt;</span><span style="color: #000000; font-weight:bold;">0</span>
      <span style="color: #804040;">echo</span> <span style="color: #C5A22D;">&quot;Not a number&quot;</span>
      <span style="color: #804040;">return</span>
    <span style="color: #804040;">endif</span>
    <span style="color: #804040;">if</span> l<span style="color: #000000;">:</span>input<span style="color: #000000;">&lt;</span><span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">||</span> l<span style="color: #000000;">:</span>input<span style="color: #000000;">&gt;</span>l<span style="color: #000000;">:</span>num
      <span style="color: #804040;">echo</span> <span style="color: #C5A22D;">&quot;Out of range&quot;</span>
      <span style="color: #804040;">return</span>
    <span style="color: #804040;">endif</span>
    <span style="color: #804040;">let</span> l<span style="color: #000000;">:</span><span style="color: #25BB4D;">line</span>=<span style="color: #25BB4D;">matchstr</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000000;">.</span>l<span style="color: #000000;">:</span>list, <span style="color: #C5A22D;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000000;">.</span>l<span style="color: #000000;">:</span><span style="color: #25BB4D;">input</span><span style="color: #000000;">.</span><span style="color: #C5A22D;">&quot;<span style="">\t</span>[^<span style="">\n</span>]*&quot;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #804040;">else</span>
    <span style="color: #804040;">let</span> l<span style="color: #000000;">:</span><span style="color: #25BB4D;">line</span>=l<span style="color: #000000;">:</span>list
  <span style="color: #804040;">endif</span>
  <span style="color: #804040;">let</span> l<span style="color: #000000;">:</span><span style="color: #25BB4D;">line</span>=<span style="color: #25BB4D;">substitute</span><span style="color: #000000;">&#40;</span>l<span style="color: #000000;">:</span><span style="color: #25BB4D;">line</span>, <span style="color: #C5A22D;">&quot;^[^<span style="">\t</span>]*<span style="">\t</span>./&quot;</span>, <span style="color: #C5A22D;">&quot;&quot;</span>, <span style="color: #C5A22D;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #804040;">execute</span> <span style="color: #C5A22D;">&quot;:e &quot;</span><span style="color: #000000;">.</span>l<span style="color: #000000;">:</span><span style="color: #25BB4D;">line</span>
endfunction
<span style="color: #668080;">command</span><span style="color: #000000;">!</span> <span style="color: #668080;">-nargs</span>=<span style="color: #000000; font-weight:bold;">1</span> Find <span style="color: #000000;">:</span><span style="color: #804040;">call</span> Find<span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;&lt;args&gt;&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Esta funcion se usa haciendo algo como</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span>Find <span style="color: #000000;">&lt;</span>nombre<span style="color: #000000;">&gt;</span></pre></div></div>

<p>Lo que hice fue que busce archivos con extension especificas [html|htm|php] y evita el directorio &#8220;.svn&#8221;. Este script se puede modificar de muchas formas, así es como me sirve a mi&#8230;</p>
<p>Otro detalle que le hice, fue hacer un keybiding para buscar directamente, sin escribir el comando.</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span>nmap <span style="color: #000000;">&lt;</span>leader<span style="color: #000000;">&gt;</span>f <span style="color: #C5A22D;">&quot;zyiw:exe &quot;</span>Find <span style="color: #C5A22D;">&quot;.@z.&quot;</span><span style="color: #C5A22D;">&quot;&lt;CR&gt;</span></pre></div></div>

<p>De esta forma con &#8221;\f&#8221; buscas el archivo en el que el cursor esta parado. OJO si cambiaste el leader de VIM que cambia el binding.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aseba.com.ar/2011/03/buscar-archivo-debajo-del-cursor-en-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Búsqueda recursiva en VIM</title>
		<link>http://blog.aseba.com.ar/2011/03/busqueda-recursiva-en-vim/</link>
		<comments>http://blog.aseba.com.ar/2011/03/busqueda-recursiva-en-vim/#comments</comments>
		<pubDate>Fri, 18 Mar 2011 14:19:25 +0000</pubDate>
		<dc:creator>aseba</dc:creator>
				<category><![CDATA[Tecnico]]></category>
		<category><![CDATA[búsqueda]]></category>
		<category><![CDATA[recursivo]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://blog.aseba.com.ar/?p=668</guid>
		<description><![CDATA[Hoy me encontré con la necesidad de corregir todos los archivos de una aplicación que hacían una llamada por ajax. Buscando un poco, encontré esto que es *muy* útil vimgrep /$.ajax/ **/*.html Después podes ver los resultados con: :copen Les dije que VIM es *GENIAL*?]]></description>
			<content:encoded><![CDATA[<p>Hoy me encontré con la necesidad de corregir todos los archivos de una aplicación que hacían una llamada por ajax. Buscando un poco, encontré esto que es *muy* útil</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">vimgrep <span style="color: #000000; font-weight: bold;">/</span>$.ajax<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">**/*</span>.html</pre></div></div>

<p>Después podes ver los resultados con:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:copen</pre></div></div>

<p>Les dije que VIM es *GENIAL*?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aseba.com.ar/2011/03/busqueda-recursiva-en-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encriptar archivos en unix</title>
		<link>http://blog.aseba.com.ar/2011/03/encriptar-archivos-en-unix/</link>
		<comments>http://blog.aseba.com.ar/2011/03/encriptar-archivos-en-unix/#comments</comments>
		<pubDate>Thu, 17 Mar 2011 22:12:00 +0000</pubDate>
		<dc:creator>aseba</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Tecnico]]></category>
		<category><![CDATA[crypt]]></category>
		<category><![CDATA[encriptar]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://blog.aseba.com.ar/?p=664</guid>
		<description><![CDATA[Como mi memoria es un asco, tengo un archivo en el disco de la mac que tiene mis passwords anotadas, y dicho archivo se hace backups todos los días por las dudas mediante time-machine.. Ahora.. ese archivo, claramente, no puede estar en texto plano así nomas así que estuve buscando alguna forma de encriptar el [...]]]></description>
			<content:encoded><![CDATA[<p>Como mi memoria es un asco, tengo un archivo en el disco de la mac que tiene mis passwords anotadas, y dicho archivo se hace backups todos los días por las dudas mediante time-machine..<br />
Ahora.. ese archivo, claramente, no puede estar en texto plano así nomas así que estuve buscando alguna forma de encriptar el archivo y que sea al menos un poco mas seguro (y de paso molesto para mi)..</p>
<p>Una forma es hacer un .zip con clave, lo cual suckea jodidamente.. buscando un poco más, encontré esto:</p>
<p>Para encriptar:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl des3 <span style="color: #660033;">-salt</span> <span style="color: #660033;">-in</span> passwords <span style="color: #660033;">-out</span> passwords.crypt</pre></div></div>

<p>Para desencriptar</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl des3 <span style="color: #660033;">-d</span> <span style="color: #660033;">-salt</span> <span style="color: #660033;">-in</span> passwords.crypt <span style="color: #660033;">-out</span> passwords</pre></div></div>

<p>Simple..<br />
Ahora tengo que buscar una forma de que encripte y desencripte on-the-fly para ver ese archivo pidiendo la clave.. Ya se me va a ocurrir un script, mientras&#8230; esto sirve</p>
<p>UPDATE:<br />
Me tiraron el dato que vim encripta archivos y despues los podes leer usando la opcion <strong>-x</strong>, es decir:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #660033;">-x</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>archivo<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.aseba.com.ar/2011/03/encriptar-archivos-en-unix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Css tip del día</title>
		<link>http://blog.aseba.com.ar/2011/03/css-tip-del-dia/</link>
		<comments>http://blog.aseba.com.ar/2011/03/css-tip-del-dia/#comments</comments>
		<pubDate>Fri, 11 Mar 2011 19:55:15 +0000</pubDate>
		<dc:creator>aseba</dc:creator>
				<category><![CDATA[Tecnico]]></category>
		<category><![CDATA[border]]></category>
		<category><![CDATA[click]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[focus]]></category>
		<category><![CDATA[outline]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://blog.aseba.com.ar/?p=660</guid>
		<description><![CDATA[*&#123; outline: none; &#125; Te borra todo los bordes cuando haces focus en cosas. El famoso borde punteado feo..]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Te borra todo los bordes cuando haces focus en cosas. El famoso borde punteado feo..</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aseba.com.ar/2011/03/css-tip-del-dia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Amo VIM</title>
		<link>http://blog.aseba.com.ar/2011/03/amo-vim/</link>
		<comments>http://blog.aseba.com.ar/2011/03/amo-vim/#comments</comments>
		<pubDate>Thu, 10 Mar 2011 13:39:33 +0000</pubDate>
		<dc:creator>aseba</dc:creator>
				<category><![CDATA[Tecnico]]></category>
		<category><![CDATA[expresión regular]]></category>
		<category><![CDATA[texto]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://blog.aseba.com.ar/?p=655</guid>
		<description><![CDATA[Si leyeron el post anterior&#8230; Quizas entiendan porque esto que estoy haciendo está bueno&#8230; :%s/^\(\d\d\)\(.*\)/&#60;li&#62;&#60;a href="images\/membranofonos\/\1.jpg"&#62;\2&#60;\/a&#62;&#60;\/li&#62;]]></description>
			<content:encoded><![CDATA[<p>Si leyeron el post anterior&#8230; Quizas entiendan porque esto que estoy haciendo está bueno&#8230;</p>
<pre>:%s/^\(\d\d\)\(.*\)/&lt;li&gt;&lt;a href="images\/membranofonos\/\1.jpg"&gt;\2&lt;\/a&gt;&lt;\/li&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.aseba.com.ar/2011/03/amo-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Renombrar archivos en batch chetamente</title>
		<link>http://blog.aseba.com.ar/2011/03/renombrar-archivos-en-batch-chetamente/</link>
		<comments>http://blog.aseba.com.ar/2011/03/renombrar-archivos-en-batch-chetamente/#comments</comments>
		<pubDate>Thu, 10 Mar 2011 13:36:29 +0000</pubDate>
		<dc:creator>aseba</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Tecnico]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[rename]]></category>

		<guid isPermaLink="false">http://blog.aseba.com.ar/?p=651</guid>
		<description><![CDATA[Ayer me encontré con un problema interesante. Resulta que estoy haciendo un laburo que consta de quichimil imágenes nombras de formas exóticas, la forma del nombre era algo como [numeros]{unmontondecosasquecambiaban}.jpeg/gif, yo necesitaba trabajar con algo mas facil de reconocer automágicamente, ademas los numeros eran consecutivos y no se repetían&#8230; no tarde mucho en decidirme en [...]]]></description>
			<content:encoded><![CDATA[<p>Ayer me encontré con un problema interesante. Resulta que estoy haciendo un laburo que consta de quichimil imágenes nombras de formas exóticas, la forma del nombre era algo como <em>[numeros]{unmontondecosasquecambiaban}.jpeg/gif</em>, yo necesitaba trabajar con algo mas facil de reconocer automágicamente, ademas los numeros eran consecutivos y no se repetían&#8230; no tarde mucho en decidirme en <em>[numeros].jpeg/gif</em></p>
<p>Bien, la cosa era como hacer ese laburo, se me ocurrió empipar cosas, y hacer cosas como</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-<span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">|</span> Algo que pase ese nombre a algo útil</pre></div></div>

<p>Pero es muy difícil sacar las partes del nombre que te hace falta y chantarselo despues de un mv. Cuando me di por vencido, me fui a un canal innombrable de IRC a preguntar.. Me tiraron el dato de un script que viene con un paquete en Debian cuando instalas xfce. El script en Debian se llama <strong>prename</strong> pero es una variación de un script mas viejo que se llama <strong>rename</strong>. Está escrito en perl y es *muy* cheto porque funciona con expresiones regulares. Esto me permitió hacer cosas como:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">perl</span> renamer.pl <span style="color: #ff0000;">'s/(\d+).*\.([\w]+)/$1.$2/'</span> <span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #000000; font-weight: bold;">*</span></pre></div></div>

<p>Si no entendes expresiones regulares.. <a href="http://es.wikipedia.org/wiki/Expresi%C3%B3n_regular" target="_blank">andá a leer sobre expresiones regulares</a>.. esto busca algo de la forma que nombré mas arriba y lo reemplaza en el nombre del archivo, borrando el anterior y dejando el nuevo con el nombre bonito.</p>
<p>Esto es genial por si no se dieron cuenta, porque permite renombrar todo lo que quieran usando estas expresiones regulares que son un bodrio pero amamos.</p>
<p>Por si les interesa el script, lo subí a <a href="https://github.com/aseba/Renamer" target="_blank">GitHub</a> y a <a href="https://bitbucket.org/aseba/renamer" target="_blank">BitBucket</a>. Y lo ejecutas con la forma que puse mas arriba. Esto va a andar en cualquier computadora que tenga perl instalado (Linux y Mac lo tienen, Windows no tengo la mas remota idea)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aseba.com.ar/2011/03/renombrar-archivos-en-batch-chetamente/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Redimensionar imágenes en CakePHP</title>
		<link>http://blog.aseba.com.ar/2010/12/redimensionar-imagenes-en-cakephp/</link>
		<comments>http://blog.aseba.com.ar/2010/12/redimensionar-imagenes-en-cakephp/#comments</comments>
		<pubDate>Wed, 01 Dec 2010 13:03:13 +0000</pubDate>
		<dc:creator>aseba</dc:creator>
				<category><![CDATA[Tecnico]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[redimensionar]]></category>
		<category><![CDATA[resize]]></category>

		<guid isPermaLink="false">http://blog.aseba.com.ar/?p=635</guid>
		<description><![CDATA[Desarrollando una app en CakePHP, me encontré con que necesitaba hacerle resize a un par de imagenes para mostrarlas en el frontend. Es un tema común en cualquier desarrollo y no debería ser tan complicado. Buscando, encontré esta solución que si bien estaba buena, en la versión de CakePHP que estoy usando no servía, asi [...]]]></description>
			<content:encoded><![CDATA[<p>Desarrollando una app en <a href="http://www.cakephp.org/">CakePHP</a>, me encontré con que necesitaba hacerle resize a un par de imagenes para mostrarlas en el frontend. Es un tema común en cualquier desarrollo y no debería ser tan complicado. Buscando, encontré <a href="http://bakery.cakephp.org/articles/hundleyj/2007/02/16/image-resize-helper">esta solución</a> que si bien estaba buena, en la versión de CakePHP que estoy usando no servía, asi que la modifiqué un poco y ahora anda. Es un helper, por lo que se puede usar directamente desde el template previamente llamándolo en el controller</p>
<p>El helper solito se encarga de hacerle el resize a las imágenes y guardarlas en el directorio /webroot/image_cache, hay que asegurarse de que ese directorio exista</p>
<p>/app/views/helpers/resizer.php</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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>  
<span style="color: #000000; font-weight: bold;">class</span> ResizerHelper <span style="color: #000000; font-weight: bold;">extends</span> AppHelper <span style="color: #009900;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$helpers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Html'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$cacheDir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'image_cache'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// relative to IMAGES_URL path </span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/** 
     * Automatically resizes an image and returns formatted IMG tag 
     * 
     * @param string $path Path to the image file, relative to the webroot/img/ directory. 
     * @param integer $width Image of returned image 
     * @param integer $height Height of returned image 
     * @param boolean $aspect Maintain aspect ratio (default: true) 
     * @param array    $htmlAttributes Array of HTML attributes. 
     * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
     * @return mixed    Either string or echos the value, depends on AUTO_OUTPUT and $return. 
     * @access public 
     */</span> 
    <span style="color: #000000; font-weight: bold;">function</span> resize<span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$aspect</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #000088;">$htmlAttributes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$types</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;gif&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;jpeg&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;png&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;swf&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;psd&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;wbmp&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// used to determine image type</span>
        <span style="color: #000088;">$fullpath</span> <span style="color: #339933;">=</span> ROOT<span style="color: #339933;">.</span>DS<span style="color: #339933;">.</span>APP_DIR<span style="color: #339933;">.</span>DS<span style="color: #339933;">.</span>WEBROOT_DIR<span style="color: #339933;">.</span>DS<span style="color: #339933;">;</span>
        <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$fullpath</span><span style="color: #339933;">.</span><span style="color: #000088;">$path</span><span style="color: #339933;">;</span> 
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>  
            <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// image doesn't exist </span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$aspect</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// adjust to aspect. </span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">/</span><span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">/</span><span style="color: #000088;">$width</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>  <span style="color: #666666; font-style: italic;">// $size[0]:width, [1]:height, [2]:type</span>
                <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ceil</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">/</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
            <span style="color: #b1b100;">else</span>  
                <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ceil</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">/</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #009900;">&#125;</span> 
        <span style="color: #000088;">$relfile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">webroot</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cacheDir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$width</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'x'</span><span style="color: #339933;">.</span><span style="color: #000088;">$height</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">.</span><span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// relative file </span>
        <span style="color: #000088;">$cachefile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$fullpath</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cacheDir</span><span style="color: #339933;">.</span>DS<span style="color: #339933;">.</span><span style="color: #000088;">$width</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'x'</span><span style="color: #339933;">.</span><span style="color: #000088;">$height</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">.</span><span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// location on server </span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cachefile</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
            <span style="color: #000088;">$csize</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cachefile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
            <span style="color: #000088;">$cached</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$csize</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$csize</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// image is cached </span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cachefile</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #339933;">@</span><span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// check if up to date </span>
                <span style="color: #000088;">$cached</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> 
            <span style="color: #000088;">$cached</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
        <span style="color: #009900;">&#125;</span> 
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$cached</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
            <span style="color: #000088;">$resize</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> 
            <span style="color: #000088;">$resize</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
        <span style="color: #009900;">&#125;</span> 
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$resize</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
            <span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #990000;">call_user_func</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'imagecreatefrom'</span><span style="color: #339933;">.</span><span style="color: #000088;">$types</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;imagecreatetruecolor&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$temp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #990000;">imagecopyresampled</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$temp</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
              <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> 
                <span style="color: #000088;">$temp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreate</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
                <span style="color: #990000;">imagecopyresized</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$temp</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> 
            <span style="color: #990000;">call_user_func</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$types</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cachefile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
            <span style="color: #990000;">imagedestroy</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
            <span style="color: #990000;">imagedestroy</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$temp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #009900;">&#125;</span>          
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">output</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tags</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$relfile</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$return</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Entonces, para poder usarlo en el template hay que agregarlo en el controller</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$helpers</span>    <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Html'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Form'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Session'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Resizer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Y finalmente, en el template</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Resizer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">150</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">150</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.aseba.com.ar/2010/12/redimensionar-imagenes-en-cakephp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Markup.io :: Web app infaltable para web development</title>
		<link>http://blog.aseba.com.ar/2010/11/markup-io-web-app-infaltable-para-web-development/</link>
		<comments>http://blog.aseba.com.ar/2010/11/markup-io-web-app-infaltable-para-web-development/#comments</comments>
		<pubDate>Mon, 29 Nov 2010 17:00:32 +0000</pubDate>
		<dc:creator>aseba</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Tecnico]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[markup]]></category>
		<category><![CDATA[util]]></category>
		<category><![CDATA[utility]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.aseba.com.ar/?p=631</guid>
		<description><![CDATA[Acabo de descubrir a traves de Online una aplicación web para hacer anotaciones sobre las páginas web y pasar las URLs con las notas Para usarlo, simplemente tenes que entrar al sitio oficial y copiar el bookmark button para usarlo Es impresionantemente útil durante el desarrollo de paginas web. Podes hacer trazos, círculos, flechas y [...]]]></description>
			<content:encoded><![CDATA[<p>Acabo de descubrir a traves de <a href="http://www.online.com.es/9410/aplicaciones-web/markup-io-comparte-enlaces-y-destaca-contenidos/?utm_source=feedburner&#038;utm_medium=feed&#038;utm_campaign=Feed%3A+Online2+%28Online%29&#038;utm_content=Google+Reader">Online</a> una aplicación web para hacer anotaciones sobre las páginas web y pasar las URLs con las notas</p>
<p>Para usarlo, simplemente tenes que entrar al <a href="http://markup.io/">sitio oficial</a> y copiar el bookmark button para usarlo</p>
<p>Es impresionantemente útil durante el desarrollo de paginas web. Podes hacer trazos, círculos, flechas y anotaciones textuales. Mi nueva webapp favorita.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aseba.com.ar/2010/11/markup-io-web-app-infaltable-para-web-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bloquear flash en Safari</title>
		<link>http://blog.aseba.com.ar/2010/11/bloquear-flash-en-safari/</link>
		<comments>http://blog.aseba.com.ar/2010/11/bloquear-flash-en-safari/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 18:29:20 +0000</pubDate>
		<dc:creator>aseba</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[Tecnico]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://blog.aseba.com.ar/?p=609</guid>
		<description><![CDATA[Bueno, hace un tiempo estoy haciendo un poco de benchmark sobre mi MacbookPro y noté que en ciertos momentos, aparte de que la temperatura del micro se va a las nubes, la batería me dura la mitad de lo que debería. Chequeando un poco los procesos que estan corriendo en la maquina, descubrí que cada [...]]]></description>
			<content:encoded><![CDATA[<p>Bueno, hace un tiempo estoy haciendo un poco de benchmark sobre mi MacbookPro y noté que en ciertos momentos, aparte de que la temperatura del micro se va a las nubes, la batería me dura la mitad de lo que debería. Chequeando un poco los procesos que estan corriendo en la maquina, descubrí que cada tanto el micro gasta 20% de los recursos en ejecutar flash en Safari. Me parece un despropósito, más cuando los flash que se están ejecutando son publicidades del diario o porquerías de esas.</p>
<p>Inmediatamente recordé flashblock para firefox, un plugin que bloquea la ejecución de flash en firefox y para poder ejecutarlo necesitas hacerle click. Navegando un poco, encontré <a href="http://clicktoflash.com/">ClickToFlash</a> que, aparte de estar buenisimo, es libre <img src='http://blog.aseba.com.ar/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Aparte del chiche obvio de ser un plugin de safari que bloquea flash, tiene un par de cosas muy interesantes, las que mas me interesaron fueron:</p>
<ul>
<li>Posibilidad de ejecutar youtube en quicktime en lugar de en el plugin de flash</li>
<li>Listas blancas para sitios que si puedan ejecutar flash sin preguntar</li>
<li>Se instala con un .pkg y se actualiza solo cuando hace falta</li>
<li><a href="https://github.com/rentzsch/clicktoflash">¡Es Libre!</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.aseba.com.ar/2010/11/bloquear-flash-en-safari/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upload de imagenes en CakePHP</title>
		<link>http://blog.aseba.com.ar/2010/11/upload-de-imagenes-en-cakephp/</link>
		<comments>http://blog.aseba.com.ar/2010/11/upload-de-imagenes-en-cakephp/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 16:00:26 +0000</pubDate>
		<dc:creator>aseba</dc:creator>
				<category><![CDATA[Tecnico]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://blog.aseba.com.ar/?p=552</guid>
		<description><![CDATA[Primero que nada, quiero decir que no soy un power developer de CakePHP ni de PHP. De hecho medio que casi no me gusta escribir PHP. Con esto dicho, tiro un pequeño snippet que uso en CakePHP para hacer upload de imágenes en cakephp usando un file input en la vista Para que entiendan mejor, [...]]]></description>
			<content:encoded><![CDATA[<p>Primero que nada, quiero decir que no soy un power developer de CakePHP ni de PHP. De hecho medio que casi no me gusta escribir PHP. Con esto dicho, tiro un pequeño snippet que uso en CakePHP para hacer upload de imágenes en cakephp usando un file input en la vista</p>
<p>Para que entiendan mejor, esto es un admin_add de una news. Una news es como un post de blog que tiene titulo, cuerpo y una imagen asociada. En la tabla solo guardo la URL a la imagen que se hizo upload.</p>
<p>Primero, el snippet de la función que hace el upload. Esto lo pongo directamente en el controller como ultimo metodo, junto con los edit, add, admin_add, view, index, whatever.</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" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> __upload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_array</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #990000;">File</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$file_base</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pathinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;;</span>
    <span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_base</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'extension'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ext</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'jpg'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$ext</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'jpeg'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$ext</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'gif'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$ext</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'png'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFlash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'You may only upload image files.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$full_path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/upload_images/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$file_array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #990000;">File</span><span style="color: #009900;">&#40;</span>WWW_ROOT<span style="color: #339933;">.</span><span style="color: #000088;">$full_path</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #b1b100;">return</span> <span style="color: #000088;">$full_path</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'Ouch!'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<blockquote><p>Si usas este ejemplo, las imagenes se guardan en wwwroot/upload_images/</p></blockquote>
<blockquote><p>Este snippet funciona con cualquier tipo de archivos, no solo con imagenes.  Es cuestión de sacarle el check que hago al tipo de extensión del archivo.</p></blockquote>
<p>Si querés ver como lo uso, vas a tener que entrar al post.. <img src='http://blog.aseba.com.ar/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p><span id="more-552"></span></p>
<p>¿Como lo uso?</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> admin_add<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'News'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__upload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'News'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">News</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">News</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFlash</span><span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'The news has been saved'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFlash</span><span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'The news could not be saved. Please, try again.'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Y si quieren ver como llamo al form en la vista</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'subtitle'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'News'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">image</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'News'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'height'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'50'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">checkbox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'active'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'publish_date'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Lo que se ve en las lineas 5 y 6, son simplemente una forma de mostrar la imagen guardada en la base de datos solo si el campo de la base *tiene* cargada una imagen</p>
<p>Un chiche. Durante el edit pasa que el form manda toda la información de vuelta al controlador, esto hace que si la imagen estaba cargada, cuando le damos send al form manda un data nuevo sin la imagen cargada (porque no hace un pre-load del input con la imagen), entonces hay que saltearse el paso de guardar la imagen si, en efecto, no hay imagen <img src='http://blog.aseba.com.ar/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> admin_edit<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$id</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFlash</span><span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Invalid news'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'News'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'News'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__upload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'News'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'News'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">News</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFlash</span><span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'The news has been saved'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFlash</span><span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'The news could not be saved. Please, try again.'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">News</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Bueno, esta es una pequeña forma que encontré de resolver los uploads en CakePHP. Probablemente hayan un montón de otras formas mas phpperas o cakephperas (por ejemplo armando un componente de esta función), pero la verdad que así me resuelve el problema y no tengo ganas de preocuparme demasiado (si, soy vago)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aseba.com.ar/2010/11/upload-de-imagenes-en-cakephp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

