dpw30157 2017-02-03 12:47
浏览 154
已采纳

警告: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条回答 默认 最新

  • douer9399 2017-02-03 12:51
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于温度改变石墨烯介电性能(关键词-介电常数)
  • ¥150 HDMI分路器LT86102 的输出在890MHz频点处EMC超标8DB
  • ¥15 druid(相关搜索:数据库|防火墙)
  • ¥15 大一python作业
  • ¥15 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
  • ¥60 如何鉴定微信小程序数据被篡改过
  • ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
  • ¥20 C#上传XML格式数据
  • ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下
  • ¥20 手机截图相片分辨率降低一半