0

I am trying to write create a file using move function. Android app is calling an API and sending image files. but on server side I am getting "Unable to write a file on \x.x.x.x\test folder.

Below code snippet is from production server which written in larvael.

 $file_upload = $file_name->move(env('SHARE_PATH'),$old_filename);

I am now trying to test share file folder access using core php function.When I write a file using fopen , I am getting success. But when I use is_readable function , it returns "False" instead of "True".

error_reporting(E_ALL);
$dir = "\\\\x.x.x.x\\transitory";
if(is_readable('\\\\x.x.x.x\\transitory\\')) {
  var_dump("$old_filename is readable");
} else {
  var_dump("$old_filename is not readable");
}
if(is_writable('\\\\x.x.x.x\\transitory\\')) {
  var_dump("$old_filename is writable");
} else {
  var_dump("$old_filename is not writable");
}
if (is_dir($dir)) 
{
    if ($dh = opendir($dir))        
        print "able to access directory tree.";  

        $myfile = fopen($dir."\\newfile1.txt", "w") or die("Unable to open file!");
        $txt = "John Doe\n";
        fwrite($myfile, $txt);
        $txt = "Jane Doe\n";
        fwrite($myfile, $txt);
        fclose($myfile);     
        }
else {   print "not access tree.";}

Output

string(16) " is not readable"
string(16) " is not writable"
string(13) "readdir false"
able to access directory tree.

Expected Result.. ABove code shoud return True and want to move a file from temp folder to shared folder.

EDIT --

It runs on IIS server and server has an access to this shared folder

kreya
  • 1,091
  • 5
  • 24
  • 52
  • Did you tell Apache that it was allowed to access `"\\\\x.x.x.x\\transitory"` If not, look up Alias in the Apache manual and add one to your Virtual Host – RiggsFolly Jan 04 '21 at 13:28
  • @ it is hosted on IIS server and server has an access to this shared folder. – kreya Jan 04 '21 at 13:33
  • I am able to write a file using fopen function but move function and is_readable functions are return false – kreya Jan 04 '21 at 13:34

1 Answers1

-1

When I was testing, the application could not read or write at first, and even fopen could not be executed successfully. Eventually I found that the problem lies in the transitory folder.

Initially I only set up the disk sharing, but did not set up the transitory in the disk. I thought the sharing permissions would be inherited, but not. So when I set up the transitory share and added the user's full control permissions, everything worked.

Right click transitory folder -> Properties -> Sharing -> Advanced sharing -> check share this folder ->permissions

enter image description here

It worked!

enter image description here

Bruce Zhang
  • 2,880
  • 1
  • 5
  • 11