Thursday, July 8, 2010

uploading and resizing images. code from "usual" php exists. transfer to cakephp??

hi,

before i used cake i coded (or mostly copied code from tuts) a
functionality to upload and resize images. i dont want to go through
that pain again and start all over again for cake and i wanna try to
use the existing code. maybe you can help me figuring out what to do:

i have an include file called "ajaxupload.php". in this file there is
all the logic. uploading, resizing and saving the picture. to do that,
some variables need to be passed.

--------------------------------------------
......
......
$filename = strip_tags($_REQUEST['filename']);
$maxSize = strip_tags($_REQUEST['maxSize']);
$maxW = strip_tags($_REQUEST['maxW']);
$fullPath = strip_tags($_REQUEST['fullPath']);
$relPath = strip_tags($_REQUEST['relPath']);
$colorR = strip_tags($_REQUEST['colorR']);
$colorG = strip_tags($_REQUEST['colorG']);
$colorB = strip_tags($_REQUEST['colorB']);
$maxH = strip_tags($_REQUEST['maxH']);
$filesize_image = $_FILES[$filename]['size'];

if($filesize_image > 0){
$upload_image = uploadImage($filename, $maxSize, $maxW, $fullPath,
$relPath, $colorR, $colorG, $colorB, $maxH);
if(is_array($upload_image)){
......
......
......
......
--------------------------------------------

as you can see a function called "uploadImage" is called with the
passed parameters. in this function it happens all :)


now from my sript "editProfile" where users can upload ther profile
pic i call "ajaxupload.php" and pass the needed variables

--------------------------------------------
<form action="includes/ajaxupload.php" method="post"
name="standard_use" id="standard_use" enctype="multipart/form-data">
<p><input type="file" name="filename" /></p>

<button onclick="ajaxUpload(this.form,'includes/ajaxupload.php?
filename=filename&amp;maxSize=4194304&amp;maxW=200&amp;fullPath=http://
localhost/login_test/uploads/&amp;relPath=../uploads/
&amp;colorR=255&amp;colorG=255&amp;colorB=255&amp;maxH=270','upload_area','File
Uploading Please Wait...&lt;br /&gt;&lt;img src=\'images/
loader_light_blue.gif\' width=\'128\' height=\'15\' border=\'0\' /
&gt;','&lt;img src=\'images/error.gif\' width=\'16\' height=\'16\'
border=\'0\' /&gt; Error in Upload, check settings and path info in
source code.'); return false;">Upload Image</button>
</form>
--------------------------------------------

now what i figured.

1st) I code a function "uploadImage" in my controller that contents
all the logic from my "ajaxupload.php".
2nd) when hitting the "upload" button in the view happens i call
this function "uploadImage" in the forms "action"-parameter in my
view !!??

what do you think? you have any idea?

thx guys....:)

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: