John Smith
John Smith

Reputation: 69

Open folder contents into directory above

In this example folder, I need to move all the contents of sub into the above directory using PHP in the move.php file.

▼ dir
  - move.php
  ▼ sub
    - a.txt
    - b.txt

After move.php is run, the files should look like this:

▼ dir
  - move.php
  - a.txt
  - b.txt

Thanks.

Upvotes: 1

Views: 92

Answers (2)

Brian
Brian

Reputation: 5028

I will give you a hint.

  1. Use php file_get_contents('file_dir') to read the file into a string
  2. Use php file_put_contents('file_dir') to create the file
  3. Also use php unlink('file_dir') function to delete a file if necessary
  4. If you need to remove directory, use php rmdir() function.

If you do not need to access the files, you can just use php copy($source, $dest) function to copy your files from one directory to another. Then you can delete them from old directory.

Upvotes: 1

Raz Harush
Raz Harush

Reputation: 739

Take a look at php scandir() function to scan your sub-directory and move files from it to your current directory.

Upvotes: 1

Related Questions