-1

My PHP code runs on windows and have the following function to create file on Linux-server connected through Windows-Exchange by IP Address (172.12.20.10).

I almost done, permission and all other important things, but still the file is not created...Why?

public function demo()
{
    $fileName='aa.json';
    $location= base_url()."test/folder";
    $Thispath = str_replace('\\', '/',$location).'/';
    $ThisFile = $Thispath.$fileName;

    $dir = '\\172.12.20.10\exchange';

    copy($ThisFile, $dir.$fileName);

    if ( !file_exists($ThisFile) ) {
        echo 'no file';
    }else{
        echo 'file exists';
        file_put_contents ($dir.'/hallo.txt', 'test File');
    }
}
   

From the above code Either the aa.json is not copied OR the hallo.txt file is not created in the exchange folder on linux!

MR.Internet
  • 547
  • 4
  • 19
  • 2
    Exchange is a mail server, not a file server. Can you elaborate as to how you reached the conclusion that an Exchange server should provide facilities to be mapped as a network drive like this…? It’s honestly not even clear how Exchange itself is a factor here. – esqew Jun 14 '22 at 14:59
  • you can access some folder on linux system through window exchange..In short I am accessing just a folder in linux and pop-up it on windows explorer... – MR.Internet Jun 14 '22 at 15:02
  • there is nothing to do with mail or Email thing at all... – MR.Internet Jun 14 '22 at 15:03
  • 2
    That looks like a URI so basically a file share and the only thing to do with Exchange is the folder name – RiggsFolly Jun 14 '22 at 15:05
  • yes. exactly file/folder share – MR.Internet Jun 14 '22 at 15:06
  • Dont you think you ought to check that the file exists `if ( !file_exists($ThisFile) ) {` BEFORE attempting to copy it? – RiggsFolly Jun 14 '22 at 15:07
  • 3
    `$filename` is 'aa.json' and `$dir` is '\\172.12.20.10\exchange', so `$dir.$fileName` will be '\\172.12.20.10\exchangeaa.json' - you probably need a "\" in between there. – IMSoP Jun 14 '22 at 15:08
  • Just to be clear, the reason people were asking about e-mail is that [Microsoft Exchange Server](https://en.wikipedia.org/wiki/Microsoft_Exchange_Server) is the name of a very popular product for handling e-mails, and you included the "[tag:exchange-server]" tag in your original question. But you seem to actually be talking about something else called "exchange"; possibly a much lesser-known piece of software that happens to have the same name? – IMSoP Jun 14 '22 at 15:13
  • The issue is both condition is not happen on linux folder...if the first has issue with "\"? why then hallo.txt can not created? – MR.Internet Jun 14 '22 at 15:14
  • Did you ever get the message `file exists` – RiggsFolly Jun 14 '22 at 15:16
  • 1
    Please post what `$ThisFile` and `$dir.$fileName` actually contain. And you _do_ call that function, right? – brombeer Jun 14 '22 at 15:17
  • ```\\``` is the escape sequence for a single backslash, but URIs start with a double backslash. So you want ```\\\\```. Alternatively, you could replace the backslashes with forward slashes which do not need to be escaped. – Ian Abbott Jun 14 '22 at 15:28
  • file exists, yes i get the message – MR.Internet Jun 14 '22 at 16:09

1 Answers1

-1

Thanks for all of your reply and answers. Unfortunately any of the above comments didn't work for me and I had forced to dig-deep to find a solution which solve my issue and at the same time it might help someone in future. Here is the solution I found and works like a charm...

  1. Go to https://awesometoast.com/php-and-mapped-network-drives/
  2. Then Follow the tutorial.

It works as perfect as it should be!

MR.Internet
  • 547
  • 4
  • 19