question

hi!

how can i access to a specific .php file inside protected?

or how I can access to a controller outside protected?

I have a widget viewer this way

<script type="text/javascript">

$(document).ready(function() {

    $("#fileUpload").fileUpload({

        'uploader': '<?php echo $uploader; ?>',

        'cancelImg': '<?php echo $cancelImg; ?>',

        ‘script’: ‘update.php’,

        'folder': '<?php echo $folder; ?>',

        'fileDesc': 'Image Files',

        'fileExt': '.jpg;.jpeg;.gif;.png',

        'multi': true,

    });

});

</script>

As far as I know you can't.

That's why protected…

Put your file outside the protected or asset it.

yes you're rigth about protected

maybe i'm just tired to think, I want to implement a widget with uploadify, the source has both js and php, with flash and jquery.

thank you anyway…

To upload files  using JavaScript (uploadify or some other fancy script), basically all I do is have an UpoadFileAction that takes care of moving the file to its destination, that way your upload script is protected.

So something like this:

Uploadify (http://www.uploadify.com/)



$('#Browse').fileUpload({	


	'uploader': 'assets/swf/uploader.swf',


	'script': 'controller/uploadFileAction',


	'folder': 'directoryHere',


	'buttonImg': 'images/browse.jpg',


	'cancelImg': 'images/icons/delete.jpg',


	'fileExt': '*.zip',


	'fileDesc': '.zip',


	'onComplete': complete,


	'width': 100,


	'height': 20,


	onerror: function (a, b, c, d) {


	         if (d.status == 404)


	            alert('Could not find upload script (controller/uploadFileAction)');


	         else if (d.type === "HTTP")


	            alert('error '+d.type+": "+d.status);


	         else if (d.type ==="File Size")


	            alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB');


	         else


	            alert('error '+d.type+": "+d.text);


	},


});





function complete(evnt, queueID, fileObj, response, data) {


	alert("We are done!");


}


UploadFileAction (note I separate my actions from the controller for greater seperation of application code)



<?php





class UploadFileAction extends CAction {


	public function run() {	


		if (!empty($_FILES)) {


			$tempFile = $_FILES['Filedata']['tmp_name'];


			$targetPath = 'directoryHere/';


			$filename = $_FILES['Filedata']['name'];


			$targetFile =  str_replace('//','/',$targetPath) . $filename;


			move_uploaded_file($tempFile, $targetFile);


		}


		echo $filename;	


	}


}


Hope that helps.

Chris

thanks for your suggestion

so far these help me to fix the part to access update.php trought the uploadFileAction

but now I'm getting other errors:

error HTTP: 403

error IO: Error #2038

protected/extensions/uploadify/views/uploadifyWidget.php



<link rel="stylesheet" href="/uploadify/uploadify.css" type="text/css" />


<script type="text/javascript" src="uploadify/jquery-1.3.2.min.js"></script>


<script type="text/javascript" src="uploadify/jquery.uploadify.js"></script>


<script type="text/javascript">


$(document).ready(function() {


    $("#fileUpload").fileUpload({


        'uploader': 'uploadify/upload.swf',


        'cancelImg': '<?php echo $cancelImg; ?>',


        'script': 'upload::controller()->upload()',


        'folder': '<?php echo $folder; ?>',


        'fileDesc': 'Image Files',


        'fileExt': '*.jpg;*.jpeg;*.gif;*.png',


        'multi': true,


        'buttonText': '<?php echo $buttonText; ?>',


        'displayData': 'speed',


        'simUploadLimit': 1,


        'onComplete': complete,


        onerror: function (a, b, c, d) {


        if (d.status == 404)


           alert('Could not find upload script (upload::controller()->upload())');


        else if (d.type === "HTTP")


           alert('error '+d.type+": "+d.status);


        else if (d.type ==="File Size")


           alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB');


        else


           alert('error '+d.type+": "+d.text);


        },


    });


    function complete(evnt, queueID, fileObj, response, data) {


           alert("We are done!");


           }


});


</script>


protected/controllers/upload/UploadFileAction.php



<?php


    class UploadFileAction extends CAction {


        public function run() {


            if (!empty($_FILES)) {


                $tempFile = $_FILES['Filedata']['tmp_name'];


                $name = substr($_FILES['Filedata']['name'], 0, -4);


                $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/' .$name;


                $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];





                mkdir(str_replace('//','/',$targetPath), 0755, true);


                move_uploaded_file($tempFile,$targetFile);





            }


            echo '1';


        }


}


?>


and protected/controllers/uploadController.php



<?php


class UploadController extends CController {





    public function actions() {


        return array(


            'upload'=>'application.controllers.upload.UploadFileAction',


        );


    }





}


?>


do you know what is wrong? thanks in advance!

403 is a forbidden error huh?

I think you are trying to access something inside /protected folder. Not sure. Just apache screaming maybe.

hey krak3n finally I got it,

I just based on your suggestion, drink a beer, thin a lot and now is working…

when I do the uploadify, implement the image extension and create diferent sizes of the image.

i hope create the extension of this asap.

thanks.

cheers!

Hi, I’m glad you got it working :)