Master Yoda
Master Yoda

Reputation: 531

Creating a folder in php apache

Here is my code to create a folder named images

$path="".Yii::app()->request->baseUrl."/users/".Yii::app()->session["id"]."/images";
        if(!file_exists($path))
        {
            mkdir($path,0777,true);
            echo($path);
        }

But the error i am having is

mkdir(): Permission denied (/var/www/yiicapp/protected/models/Statement.php:123)

I am logged in as "bhawin" but it is making owner www-data

Upvotes: 0

Views: 488

Answers (4)

Krish R
Krish R

Reputation: 22711

Yii::app()->request->baseUrl it is domain path URL such as http://example.com/yourfolderpath instead of that you can use relative path of the folder like /var/www/.....

Upvotes: 1

Elon Than
Elon Than

Reputation: 9765

You've got no right to write to given folder and PHP can't change it. You have to use SSH or FTP with user with permissions and change rights to 777.

Upvotes: 1

Jon
Jon

Reputation: 437386

Yii::app()->request->baseUrl is a URL, not a local filesystem path. You cannot create directories in a URL.

To work with the filesystem you would need to start from Yii::app()->basePath instead, although putting user-supplied content in a web-accessible location might not be smart (everyone can view that content if they know the correct URL). Depending on what the content is the correct approach might be to put it outside the web server document root entirely.

Upvotes: 0

Littlebobbydroptables
Littlebobbydroptables

Reputation: 3731

http://pt1.php.net/chmod

You have no rights to create a new folder, so chmod is probably what you need :)

Upvotes: 0

Related Questions