PHP Code:
<?php
mkdir("filesscreate",0777);
copy('admin','filescreate');
?>
This is PHP code to copy the file from existing folder into new folder. I error after executing the program. Please help me out
PHP Code:
<?php
mkdir("filesscreate",0777);
copy('admin','filescreate');
?>
This is PHP code to copy the file from existing folder into new folder. I error after executing the program. Please help me out
First you make a directory then set a permission to copy the files. Take a example
PHP Code:
<?php
copydir("admin","filescreate");
echo "done";
function copydir($source,$destination)
{
if(!is_dir($destination)){
$oldumask = umask(0);
mkdir($destination, 01777); // so you get the sticky bit set
umask($oldumask);
}
$dir_handle = @opendir($source) or die("Unable to open");
while ($file = readdir($dir_handle))
{
if($file!="." && $file!=".." && !is_dir("$source/$file"))
copy("$source/$file","$destination/$file");
}
closedir($dir_handle);
}
?>
In this code I made one SOURCE directory (have permission to read)and another is DESTINATION directory(have permission to write)
It code filescreate is to be created in the same root directory where ADMIN resides. If you wish to copy filescreate inside another directory then you would have to make sure the directory has permission.
<?php
$file = 'example.txt';
$newfile = 'example.txt.bak';
if (!copy($file, $newfile)) {
echo "La copie $file du fichier a échoué...\n";
}
?>
I tried to copy a file from /tmp to /var/www/html.
But i always get an permission denied (even after a chmod 0777 to the /var/www/html directory)
After spending a lot of hours searching for my error, I found it.
But not where I thought it....It was the turned on SELinux.
(Fedora 15).So i do a echo 0 >/selinux/enforce and everything works perfect
<?php
$from =\\'
$to=\\'./somefile.zip\\';
if (!@copy($from,$to)) {
$errors= error_get_last();
echo \\"COPY ERROR: \\".$errors[\\'type\\'];
echo \\"<br />\\\\n\\".$errors[\\'message\\'];
} else {
echo \\"File copied from remote!\\";
}
Bookmarks