-1

Can I programmatically change the path to a file using PHP?

For example, change D:\ISO & SOFT\test.txt to D:\test.txt.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sanya
  • 57
  • 8
  • You can change directory within the exec command ( **exec("cd Scripts && ./script.sh")** ) or you change the working directory of the PHP process using chdir(). – sT0n3 Jun 20 '17 at 11:35
  • Do you want to move the file [ _test.txt_ ] from D:\ISO & SOFT\ to D:/ ? – Vivek D. Jun 20 '17 at 11:47
  • 1
    If you want to move the file then your questions is a duplicate. This question has already been asked [here](https://stackoverflow.com/a/19139524/2231819). The current answer of @PrabhuNandanKumar was also stolen from there. :P – rayphi Jun 20 '17 at 11:58

1 Answers1

0

For this purpose you can simple move the file from the present path to the desired path.

Use the following steps for moving a file in PHP:

$uploads_dir = '/uploads'; // Desired path
foreach ($_FILES["pictures"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
        $name = $_FILES["pictures"]["name"][$key];
        move_uploaded_file($tmp_name, "$uploads_dir/$name"); //Moving file at desire path
    }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Prabhu Nandan Kumar
  • 1,205
  • 12
  • 22