警告:file_get_contents无法打开流:没有这样的文件或目录? [重复]

This question already has an answer here:

Here in this Iam uploading a file and then trying to send this file to another VM.

Code here

// Debugging information -- No use in output    
echo "</p>";
echo '<pre>';
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
$file_name = $_FILES['userfile']['name'];
echo $file_name;
echo gettype($file_name);
echo "<br/>";

Output:

Here is some more debugging info:Array
(
    [userfile] => Array
        (
            [name] => 6274e8cb0358ef3e3906a91036bc84138a8fde606a6e926b9a580c79f9cfc489
            [type] => application/octet-stream
            [tmp_name] => /tmp/php3Yt3T5
            [error] => 0
            [size] => 3107800
        )

)
6274e8cb0358ef3e3906a91036bc84138a8fde606a6e926b9a580c79f9cfc489string

And it is printing the details correctly.But when i try to send this file to remote VM,it is creating errors.

Code continuation

$localFile='/var/www/uploads/$file_name';
echo $localFile;
$remoteFile='/home/nsadmin/$file_name';
$host='192.168.150.85';
$port=22;
$user='someusername';
$pass='somepassword';

$connection= ssh2_connect($host,$port);
ssh2_auth_password($connection, $user, $pass);
$sftp = ssh2_sftp($connection);

$stream = fopen("ssh2.sftp://$sftp$remoteFile", 'w');
$file = file_get_contents($localFile);
fwrite($stream, $file);
fclose($stream);

Error Log:

 /var/www/uploads/$file_name Warning: file_get_contents(/var/www/uploads/$file_name): failed to open stream: No such file or directory in /var/www/MTP/upload.php on line 111 

Any suggestions on how to fix this error.

P.S :

I have used these for debugging at the start of php file

error_reporting(E_ALL);
ini_set('display_errors',1);
ini_set('log_errors',1);
</div>

3个回答



尝试这样的字符串可能有帮助</ p>

只需使用。 用于连接。</ p>

  $ localFile ='/ var / www / uploads / $ file_name'; 
</ code> </ pre>

to </ p>

 <代码> $ LOCALFILE ='/无功/网络/上传/'.$ file_name中; 
</代码> </ PRE>

和</ p>

 <代码> $参数】remotefile = '/家/ nsadmin / $ FILE_NAME'; 
</代码> </ PRE>

到</ p>
\ n

  $ remoteFile ='/ home / nsadmin /'.$ file_name; 
</ code> </ pre>
</ div>

展开原文

原文

Try string like this it may help

Just use . for concatenating.

$localFile='/var/www/uploads/$file_name';

to

$localFile='/var/www/uploads/'.$file_name;

and

$remoteFile='/home/nsadmin/$file_name';

to

 $remoteFile='/home/nsadmin/'.$file_name;



更改</ p>

  $ localFile ='/ var / www / uploads / $ file_name  '; 
</ code> </ pre>

</ p>

  $ localFile =“/ var / www / uploads / $ file_name”; \  n </ code> </ pre> 

$变量未在'引号</ p>中解析

另一种方式</ p>

 <  code> $ localFile =“/ var / www / uploads /".$ file_name; 
</ code> </ pre>

与遥控器相同。</ p>
</ div>

展开原文

原文

change

   $localFile='/var/www/uploads/$file_name';

to

   $localFile="/var/www/uploads/$file_name";

$variables are not parsed inside ' quotes

Another way just

   $localFile="/var/www/uploads/".$file_name;

Same with remote.

php中的



你不能在单引号中使用变量使用双引号或使用字符串外的变量</ p>

  $ localFile ='/ var / www / uploads / $ file_name'; 
</ code> </ pre>

将其更改为</ p>

< 预> <代码> $ LOCALFILE ='/无功/网络/上传/'.$ FILE_NAME; 或$ localFile =“/ var / www / uploads / $ file_name”;
</ code> </ pre>
</ div>

展开原文

原文

in php you can't use variable in single quotes use double quotes or use variables outside the string

$localFile='/var/www/uploads/$file_name';

change it to

$localFile='/var/www/uploads/'.$file_name; or $localFile="/var/www/uploads/$file_name";

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐