Am a beginner in php. My problem is, i use the following code to create a directory and copy some files into it(I used a code get from so itself). The code works fine directory is created and files are copied. But I am getting a warning like this.
function copyr($source, $dest)
{
// Simple copy for a file
if (is_file($source)) {
chmod($dest, 0777);
return copy($source, $dest);
}
// Make destination directory
if (!is_dir($dest)) {
mkdir($dest);
}
chmod($dest, 0777);
// Loop through the folder
$dir = dir($source);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Deep copy directories
if ($dest !== "$source/$entry") {
copyr("$source/$entry", "$dest/$entry");
}
}
// Clean up
$dir->close();
return true;
}
copyr("agentSourcefolder", "testTemp5");
.
Warning: chmod() [function.chmod]: No such file or directory in /home/websiteName/public_html/php_file_upload2.php on line 9
I have to get the response from server after this, what should i do? I used
header("Location: http://www.websiteName.com/");
But it shows the following error
Warning: Cannot modify header information - headers already sent by (output started at /home/websiteName/public_html/php_file_upload2.php:9) in /home/websiteName/public_html/php_file_upload2.php on line 41
And if the directory is already created this code works fine
This one:
is because you are passing the
header('location:')call after anything has been written to the screen. All of this processing should be done before anything is written to the page, like echo, breaking out of php, etc. Also make sure there’s NO white space before the opening<?phpline.The other error is likely because a file you’re trying to chmod doesn’t exist or exist yet. Or that you may need to provide an absolute path to mkdir. like
$_SERVER['DOCUMENT_ROOT']."/path-to-new-dir/"