Wednesday, November 16, 2011

Trying to use JavaScript and PHP with CakePHP

Hey there,

I'm a beginner with only a little php and not much JS. I'm trying to
use this image upload script (http://atwebresults.com/
php_ajax_image_upload/
) in the context of a cakephp app and struggling
(I believe) because I can't figure out how to call things properly.

The script uses an onchange to watch a file input in a form. When
someone selects a file it fires a JS file which creates an iframe with
0 width and height (invisible), attaches it to the document, changes
the form's target to point at the iframe, adds an onload function to
the iframe and submits the form.

The form submits to a php file which does the upload and returns some
html containing the src of the image to the iframe, which, when it
loads, fires the JS function which copies the iframe content into a
div on the page and then removes the iframe altogether.

I know to include the JS in the view: echo $javascript-
>link('ajaxupload.js');

But I'm not sure the php file is firing, I've tried moving the
contents into a function in my controller but I'm not sure I'm doing
it right, the bit I believe is wrong is where I have to plug in the
path to the php file. According to the instructions the initial
onchange event should pass several variables to the JS, the 2nd one
being a path to the php file plus some other variables. Here's the
beginning of the one in the example:

<input type="file" name="filename" onchange="ajaxUpload(
this.form,
'scripts/ajaxupload.php?
filename=name&amp;maxSize=9999999999&amp;maxW=200&amp;fullPath=http://
www.atwebresults.com/php_ajax_image_upload/uploads/&amp;relPath=../uploads/&amp;colorR=255&amp;colorG=255&amp;colorB=255&amp;maxH=300',

It's that second variable - scripts/ajaxupload.php?filename etc etc
which I'm not sure about. Like I say, I've tried different
configurations like moving the file around different folders ormoving
the contents of the file into it's own action in the controller but to
no avail.

Can anyone please help me out? I'll pay money if needs be! BTW I know
there's loads of great image upload plugins in the bakery but none of
them seem to do exactly what this one does (which is doesn't refresh
the page but still passes back the img url so the image can be shown
on the (non-refreshed) page.

The form the page is on is 'controller'=>'campaigns',
'action'=>'dashboard' in case that makes any difference

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate