Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:21:47+00:00 2026-06-10T15:21:47+00:00

Am a beginner in php. My problem is, i use the following code to

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:21:48+00:00Added an answer on June 10, 2026 at 3:21 pm

    This one:

    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
    

    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 <?php line.

    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/"

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm a beginner to php. i need to use php function which process some
I am little more than beginner PHP programmer and just recently started to use
PHP beginner working from a tutorial. I'm trying to do a simple upload from
I'm beginner with PHP and I try to use preg_math_all to split a string.
I am a PHP beginner and I want to do the following: I want
I'm a beginner in php, and I am trying to create a login and
I'm a beginner. I write simple json jquery php code to help understand the
I'm a beginner PHP coder, recently I've been told I indent my code not
I'm an beginner in php/msql, and need help to solve this problem: I have
I'm still beginner in PHP. I have a small problem, I would to multiply

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.