access an image inside protected

Hi!

Maybe someone can help me with my problem.

I need to call a php file in my view using <img src="…php">

It works if my php file is outside protected but it does not work if my file is inside.

Is there any way to reach an image or in my case, a php file, located inside protected folder doing something like this:


<img src="root.to.my.application./PROTECTED/folder.to.my.file/myPhpFile.php">

I tried to do:


$url = createUrl('myController/myAction');

<img src=$url>

and inside myController/myAction call myPhpFile, but it does not work.

could I do it modifying htaccess maybe?

If you have any idea, please help me.

Thank you!

I would STRONGLY suggest not to hardcode script files in your image tags or to put any executable scripts outside your protected folder. This is a potential security risk. Try to wrap the logic inside a widget and use that to output the appropriate image tags. If you need a thumbnail creator (just guessing) you could use something like http://www.yiiframework.com/extension/ephpthumb or http://www.yiiframework.com/extension/justintimeimageresizer to create thumbnails on the fly if needed.

So the question merely is: What do you want to achieve with your script?

Yes, you could, but you should not. Inside /protected there is a .htaccess file with:




deny from all



You should rather think of a way how to accomplish that, without exposing your script. The way you suggested, you would also have to duplicate code, because createWebApplication() is just called in the entry script (index.php). Without going through this you either have to call createWebApplication() another time or you can’t usee yii advantages.

Take a look at Haensel’s post on how you can achieve this, without having to change your .htaccess and duplicate code.

Thank you both of you for your answers. ;)

Haensel,

I have downloaded "JpGraph" that is graph library; and the only way, I have found, to run it and insert a graph into my view is writing in my view:


<img src="my JpGraph script">

I guess there is a better way to do it but I do not how.

I am going to see if I can do it with a widget, as you have told me.

Thanks!

You could also use a symlink

I was also on the same situation. What I did was copy the jpgraph files into /protected/vendors.

Then on the controller I create actions that will create the graphs.

Example:




 public function actionSimpleLine1Graph() {


        Yii::import('application.vendors.jpgraph.*');


        require_once ('jpgraph.php');

        require_once ('jpgraph_line.php');


// Some (random) data

        $ydata = array(11, 3, 8, 12, 5, 1, 9, 13, 5, 7);


// Size of the overall graph

        $width = 350;

        $height = 250;


// Create the graph and set a scale.

// These two calls are always required

        $graph = new Graph($width, $height);

        $graph->SetScale('intlin');


// Create the linear plot

        $lineplot = new LinePlot($ydata);


// Add the plot to the graph

        $graph->Add($lineplot);


// Display the graph

        $graph->Stroke();

    }



Next I created another action on the controller to render the view file.

On the view file I put there the image tag then the url to the controller action that will create/draw the jpgraph image.




<img src="<?php echo Yii::app()->createUrl('/controller/simpleline1graph')?>" alt="<?php echo Yii::app()->createUrl('/controller/simpleline1graph')?>" class="decoded">



Hope these could help.