I'm currently working on a website admin panel,
I added a form that adds clients to the database, what I want to do now, is to create folders for them via PHP.
So I tried to do that using the function: mkdir(),
The problem is, that when I tested the function on my "Xampp" server, it all worked just as i wanted it to.
But when I moved the file to the real host that I will use via FTP, and It just wont work the same..
ill try to explain whats wrong..:
mkdir('folderName'); //this will create a folder that i cant access through the FTP
mkdir('folderName', 0777); //creates a folder that i can access, but cant open other folders in it and cant change chmod permissions
I also need to create some nested folders for example:
mkdir('folderName/anotherFolder',0777,true); //this works on the host but again, the folders are not letting me change chmod permissions and cant create folders in them
in my xampp server i could create a few folders in a given path for example:
mkdir('folderName');
mkdir('folderName/one');
mkdir('folderName/two');
the above examples arent working on my host..
So yea sorry for writing so much, I just thought that you guys need to know those things..
Anyways, thanks in advance!
Try chgrp as well as chmod.
Other than that, the best solution in such ostensible FS situations is to do it via FTP. Major frameworks do this (including Joomla and Wordpress).
Probably you are not the owner of files/directories created by PHP script.
Related
I'm using the PHP copy function to copy a file from one folder to another. But if the folder I'm copying to is a Dropbox folder, it doesn't work. This works fine and the file is copied into the test2 folder:
copy('c:/test/test.txt','c:/test2/test.txt');
This doesn't work and the file is not copied:
copy('c:/test/test.txt','c:/Dropbox/test.txt');
Dropbox is my root Dropbox folder. Does anyone know of why this is happening and what I can do to fix this? I'm using IIS and PHP on Windows Server. Thanks in advance.
Make sure your path is exactly as it appears to be. Also consider case sensitivity. That is usually a problem that throws me off. Also make sure that all permissions to the 3rd party app are validated.
So I figured out the issue. It was an issue with the permissions on the Dropbox folder. For some reason when Dropbox created the folder, it doesn't allow the folder to inherit permissions. To fix this, I right-clicked on the Dropbox folder, selected Properties, went to the Security tab, clicked on Advanced, and then selected enable inheritance.
This allows the Dropbox folder to inherit permission from it containing folder and fixed my issue.
So I created a couple of directories and files with FTP, thus the owner is the username I use to login to the server. Now I'd like to allow users of the website to upload images to those directories. Unfortunately for the website to store images, it should be owned by Apache. How can I fix this? I've been reading around on this but can't directly find an answer.
I don't have SSH, so I guess all command-line-things are not applicable for me.
Edit
I tried to then make the folders again using apache, but now ofcourse I can't write any files using ftp into those directories.
Provided that at least the one directory is writeable by the apache user (lets call this directory 'writeabledir', it may be your root dir '/'), you must delete the folders you created via ftp and create a php script to create the directories you need.
If for example you want a directory called users and inside it another directory called upload
Create file makedirs.php on your server.
<?php
$oldumask = umask(0);
mkdir("writeabledir/users/upload",0777,true); // or even 01777 so you get the sticky bit set
umask($oldumask);
?>
Now run your makedirs.php once, by calling your.serv.er/makedirs.php on your browser
EDIT:
If you don't want to delete and recreate your directories,you could always try to change file permissions from ftp.
For exampe with FileZilla, just right click on the desired folder and set permissions to 777. If your ftp user does not have permission to do this, then there is no other way, except from asking an administrator to do this for you.
EDIT2:
Added umask to ensure that folders created by apache are writeable by everyone. (taken from http://us3.php.net/manual/en/function.mkdir.php#1207 )
Friend looks I work in php, some versions change the way of solution, however the most common is already that you want to store it would be necessary to create a database and import it to esu code that also serves to some images you want to come place, plus the wisest thing to do and you create a database with the fields necessary for its realization, import, put in a file directory of your schedule, you also advise using aptana Studio 3 greatly facilitates the creation of codes among many things and low xampp it already comes with apache integrated in one place will help you a lot any questions on installation just look at youtube he will describe
I'm having trouble with Yii's Asset Mananger. I've built several widgets for my app that try to write to the folder. Same issue when the framework tries to write it it. On each pass it I get a copy denied error. Then I set the folder path back to 0777, it works and so on...
I'm not sure why this is happening. Is this enough info for an accurate answer?
You have to give write access for apache to the assets folder.
Hmm I use Yii for some time now and the only instances where I tried to write to the Assets Folder was right in the beginning when I didn't know how it worked...
Perhaps you should do whatever changes you need before you publish the assets. I think that would solve your problem.
Other than that, I think you could chown the assets folder to www-data or whatever other username apache uses (that's if you're using mod_php). If you don't know whether or not you're using mod_php, you probably are using it.
I think this question should be something easy but after searching all over the web I couldnt find an answer, so I decided to ask here.
I have a file uploader in my website that works with php. The folder where files are being uploaded has 777 chmod. I also have a php script to list the files in that folder. What I need is to allow php to upload and browse files on that folder, but dont allow people to do it. The only solution I imagined is to chown that folder to another user different than default, so I could later chmod in filezilla and allow only owner to do it, so people will see the files trough the output of the php script, but not if they navigate to that folder.
Im using Debian, apache2. Id like to know what could I do.
To make it shor, my aim: allow php to upload, read, write and execute files in that folder, but not clients unless they use my php script.
Thanks in advance
Put all the files you're talking about in their own directory. Add a .htaccess file to that directory. The contents of the .htaccess should be deny from all.
This will prevent any user from manually accessing the files as access will be blocked off. Your PHP script can still browse the contents of the file and serve it up as an attachment with the correct content type.
For more info on how to serve a file for download in PHP, read this: https://serverfault.com/questions/316814/php-serve-a-file-for-download-without-providing-the-direct-link
All services including web servers run in a security context which is an account in the OS, for example apache starts using apache user in apache group. It is enough to change mode and change owner to this user and group. Never chmod a directory to 777 until there is a good explanation for that. Using this trick, web service process only can read, write and execute in that directory.
As well, if you want the browser clients not to see(read) the contents of that directory, you should deny listing on that directory. I think it is disabled for default.
i'm using Xampp. When I tried to do this earlier, it worked, but now it is not working.
I'm trying to make a directory in my www folder to hide it from baddies who steal files.
Each user gets their own folder in uploads to put their files on.
Xampp uses apache, and Xampp is a local web server. It allows me to design websites without the need of an online host. The www folder is in my C:\program files\xampp\php\www\ and I need to make a directory there. I know it's possible because i've done this before, I have just forgotten how to make it happen.
When I make a directory I use:
$uploaddir1 = "xampp/php/www/uploads/".$esclcusername."/";
mkdir($uploaddir1,0777);
Do I need to include C:\program files\ before xampp?
And finally, how would this be possible on a real online web host?
I saw your question here and searched some on google. This is what i found:
mkdir("D:/hshome/rubygirl58/gameparody.com/clansites/".$sitename."/lib", 0777)
So yes, I think you have to include the complete path.
Greetings,
Younes
you need to make sure that you give permisions to the parent folder to create dirs in it (0777)
to get the full path you can use dirname(FILE) wich will return the path for the directory of the file in wich it is runned