PHP can't copy file to Dropbox folder in Windows - php

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.

Related

Azure App Services File Access

I've got a few files on wwwroot/uploads which need to be publicly accessible by anyone.
It currently throws a 404 Error, but the file exists, and the URL I'm using is correct. Can anyone guide me to configuring the access controls to this folder?
I've tried using .htaccess files (allow all), and also tried messing with the web.config file. No luck though. (The access attributes need to be applied recursively to all children of the 'uploads' directory.
Thanks all!
Update:
The problem was IIS was not configured to support the .mp4 MIME type I was trying to use. Just added that in there in the main web.config file and it works now :)
Thanks to #misaim for his help :)
This could be due to the MIME type not being enabled for media files by default. Try removing the web.config and enabling mp4 or image file and see if your errors go away.
https://en.wikipedia.org/wiki/Media_type
Have you tried changing the Systems permissions of the files? Not just the web server permissions? i.e. chmod -R 777 (Don't actually do this, use correct permissions, this is to open).

PHP change folder owner to apache

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

Security risk in setting PHP file permissions to full

I'm running XAMPP on Ubuntu, and I copied the lampp folder to /opt/. I also downloaded CodeIgniter to htdocs/, and created and modified some files in it, including changing their permissions. Are there files in CodeIgniter that I shouldn't set permission to full, because maybe then once I upload them onto a server anyone can see their contents?
Ideally, your CodeIgniter should be setup such that the application and system folder lie outside your document root. Only the index.php file along with any assets (images, javascript, css etc.) should lie within the document root.
As for file permissions, 755 works fine. There's no need for full permissions 777.

PHP > mkdir path issues

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.

MKDIR is not working correctly?

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

Categories