Unable to access network drive in PHP - php

I'm facing an issue in PHP where I can't open a file located on a network drive for reading
I have tried a lot of different path name
$file = fopen('G:/Folder/vak.xlsx', 'r');
$file = fopen('//10.X.X.X/Folder/vak.xlsx', 'r');
$file = fopen('\\\\10.X.X.X\\Folder\\vak.xlsx', 'r');
But I always get the same error
Could not open "G:/Folder/vak.xlsx" for reading! File does not exist.
I have read a lot of post related to this issue and try all the solutions that i've found, but nothing works.
The network drive is mapped on the server under G: and the apache service is launched with a domain user account who's allowed to access to the network drive.
The server is running WAMP (Apache + Mysql + PHP 5.6)
I don't know why it's not working. Maybe someone has already solved this issue.
EDIT :
I have also try to use scandir() like this :
$files = scandir('\\\\10.X.X.X\\');
var_dump($files);
And I get
The network name cannot be found. (code: 67)

Related

scandir/opendir wont work with ssh2.sftp?

if i try the following command:
$_content = file_get_contents("ssh2.sftp://".intval($sftp)."/Lorem-62398848890105_20190117-101229.txt");
it works and i get the correct content.
But whenever I want to have all the files of the remote folder, the directory can not be opened.
I tried scandir or opendir. Both of these raises this message:
Warning: scandir(): Unable to open ssh2.sftp://12/ on remote host
What im doing wrong? Some tips would really help me.
Regards
Context: I use PHP 7.0.32 and ssh2.so is fully installed
UPDATE: I got it. I think it is due to a wrong attitude of the provider.
How it works:
$handle = opendir("ssh2.sftp://".intval($sftp).ssh2_sftp_realpath($sftp,".").'./');
The function ssh2_sftp_realpath + './' do the trick.

Upload to another domain (same server)

I put permission 777 on the other server I can send the file, but when access the file shows internal server error 500
This is related to the permission of owner I think, someone knows how I can solve? Obs: I already tended all types of file permissions and all that let me send the file shows the error 500
$dir_https_braip = "/home/braip/public_html/https/";enter code here
$dir_https_way = "/home/waycash/public_html/dir/https/";
$dir_https_pega = "/home/pegatudo/public_html/dir/https/";
if(!copy($_FILES['file_upload']['tmp_name'], $dir_https_braip . $nome)){
die('erro');
}

Owncloud webdav access from php

I'm trying to access my owncloud webdav interface and get the list of files in the root directory from PEAR WebDAV Client. I'm trying the following:
include("HTTP/WebDAV/Client.php");
$client = new HTTP_WebDAV_Client_Stream();
$user="admin";
$pass = "q1w2e3r4";
$dir = "webdavs://".$user.":".$pass."#127.0.0.1:10081/owncloud/remote.php/webdav/";
$stuff = $client->dir_opendir($dir, array());
var_dump($stuff);
var_dump($client->dirfiles);
The code print false, false, and when I've tried to debug it, I saw Connection refused error in Socket.php, when it tried to call the function
fsockopen("127.0.0.1", 10081, $err, $errstr);
It's even more strange since I can access this server and list the directories from cadaver though. Also I can access the test DAV server with my code by replacing my $dir variable:
$dir = "webdavs://".$user.":".$pass."#127.0.0.1:10081/owncloud/remote.php/webdav/";
It's an ugly hack, but if you add something similar to:
var_dump($err->getMessage());
to /usr/share/php/HTTP/Request.php on line 739, you should be able to see the most relevant error message. (If that is where Request.php got installed to.)
Unfortunately, there doesn't appear to be a mechanism in place in the underlying HTTP_Request package for raising that specific error message back to the HTTP_WebDAV_Client_Stream code.

PHP ftp_delete can't find file

When I try to use ftp_delete() I get the error: Warning: ftp_delete(): File not found. My ftp server should be working fine, I can upload files fine to the same directory without a problem. Here is the PHP:
$fileSource = 'http://localhost/user/images/dfdf.png';
$ftpCon = ftp_connect('localhost');
ftp_login($ftpCon,'---','---');
ftp_delete($ftpCon,$fileSource);
Also when I look at the server logs I can see I get the message: 550 File not found
The url for $fileSource is the file's exact path, I went into localhost and copy/pasted it into the code, still for some reason it can't be found.
The ftp_delete function acccepts a path to the file. You are providing http://localhost/user/images/dfdf.png which contains the host (http://localhost/). I think you mean to provide /user/images/dfdf.png, which is just the path.
Example:
ftp_delete($ftpCon, '/user/images/dfdf.png');
When, for example, your FTP root is /user/, it will mean you need to provide ftp_delete with /images/dfdf.png. Thanks to #maremp.

Amazon S3 putObject() - not working - PHP

I'm using the standalone PHP-S3 class:
http://undesigned.org.za/2007/10/22/amazon-s3-php-class
I've tried all the ready made tutorials, downloaded the source, changed the corresponding variables (set my bucket, access_key, access_secret).
I'm guetting the following error whenever I try to upload any file:
Warning: S3::putObject(): [417] Unexpected HTTP status in C:\Users\Jad\Dropbox\www\test\S3.php on line 312
Note: My bucket already exists and I even allowed all the permissions to the user everyone (temporarily for it to work but it's still not working)
I had the same problem.
If you are connected through a proxy in my case it worked connection to S3 over SSL.
$s3 = new S3(S3KEY, S3SECRET, true);
So I created a new bucket in the US (the last one was in Ireland) and everything works smoothly now.
I had the same problem. I'm connected to a proxy... If I'm connected to an other network, it works :)
I've had this issue behind a squid3 proxy and the problem was resolved by the following squid configuration directive:
ignore_expect_100 on

Categories