doufei2328 2016-11-23 15:47
浏览 201
已采纳

无法打开本地文件,但文件在那里

I have a php artisan command that I created, and executed as bheng user

php /home/forge/site.com/artisan products:exportdiff --env=production

that export the file into my /files/product-exports/ directory

Also, I've already did

chmod -R 777 files/product-exports/

Result

The export part is working fine, I got the file exported as you can see in the image below

enter image description here But I kept getting this

enter image description here

What is the different between white and green color code ?

Why does it place under the dot . ?

Does it mean anything at all ?


Question

Is this something that have to do with the permission ?

How would one go about and debug this further ?


I'm opening to any suggestions at this moment.

Any hints / suggestions / helps on this be will be much appreciated !


Update

As requested from @Tensibai

cd /home/forge/site.com/ && pwd && php /home/forge/site.com/artisan products:exportdiff --env=production

/home/forge/site.com

.
Export created successfully. Export ID is 1085
Source: /home/forge/site/files/product-exports/export1085_2016-11-23.csv
Destination: /Site/inbound/products/productexport1085_2016-11-23.csv
$source NOT exist !



  [Exception]                                                                                              
  Could not open local file: /home/forge/site/files/product-exports/export1085_2016-11-23.csv.  



products:exportdiff

Update2

$source = /home/forge/site/files/product-exports/export1088_2016-11-23.csv

I've tried dd(file_exists($source));

It kept return bool(false)

Is it because of the way I check for file_exists ?


Update3

Here is my whole PHP code for ExportProductsDiff.php

<?php

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class ExportProductsDiff extends Command {

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'products:exportdiff';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Export all products to Diff.';

    /**
     * The system export message.
     *
     * @var string
     */
    protected $system_message = '[System Diff Export]';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function fire()
    {
        // Export the products by calling the ExportProducts Command
        $options = [
            '--format'          => "distributor",
            '--encoding'        => "standard csv",
            '--categories'      => "all categories",
            '--conjugate'       => 1,
            '--include_disabled'=> 1,
            '--export_notes'    => $this->system_message
        ];

        // Run the export
        $this->call('products:export', $options);

        $last_run_export = ProductExport::where('notes', '=', $this->system_message)
            ->where('status', '=', 'finished')
            ->where('format', '=', 'distributor')
            ->orderBy('id', 'desc')
            ->firstOrFail();
        $this->info('Export created successfully. Export ID is ' . $last_run_export->id);

        $env = $this->option('env');
        if ($env == 'production'){
            $localdomain = '*******';
        }else{
            $env = 'development';
            $localdomain = '*******';
        }

        $sftp_server = '*******';
        $sftp_user_name = '*******';
        $sftp_user_pass = '*******';

        // Open the SFTP connection
        $connection = @ssh2_connect($sftp_server);
        if (!$connection)
        {
            throw new Exception("Could not connect to $sftp_server.");
        }

        // Login to the SFTP server
        if (! @ssh2_auth_password($connection, $sftp_user_name, $sftp_user_pass))
        {
            throw new Exception("Could not authenticate with username $sftp_user_name " .
                "and password $sftp_user_pass.");
        }
        $sftp = @ssh2_sftp($connection);
        if (!$sftp)
        {
            throw new Exception("Could not initialize SFTP subsystem.");
        }

        // Prepare the files
        $source = '/home/forge/site/files/product-exports/' . $last_run_export->file_name;



        /////////////////////////////////////
        //The bug is here 
        // update site to site.com 
        /////////////////////////////////////




        $destination = '/Site/inbound/products/product' . $last_run_export->file_name;

        $this->info('Source: ' . $source);
        $this->info('Destination: ' . $destination);

        if (!file_exists('/Site/inbound/products/')) {
            ssh2_sftp_mkdir($sftp, '/Site/inbound/products/', 0775, true);
        }

        dd(file_exists($source));

        if (file_exists($source)) {
            chmod($source, 0775);
        }else{
            $this->info('$source NOT exist !');
        }

        // Upload the file
        $stream = @fopen("ssh2.sftp://$sftp$destination", 'w');

        if (!$stream)
        {
            throw new Exception("Could not open file: $destination");
        }

        $data_to_send = @file_get_contents($source);
        if ($data_to_send === false)
        {
            throw new Exception("Could not open local file: $source.");
        }

        if (@fwrite($stream, $data_to_send) === false)
        {
            throw new Exception("Could not send data from file: $source.");
        }

        @fclose($stream);

        // Delete the export when finished
        if (file_exists(base_path() . ProductExport::path . $last_run_export->file_name))
        {
            unlink(base_path() . ProductExport::path . $last_run_export->file_name);
        }
        $last_run_export->delete();
    }

    /**
     * Get the console command arguments.
     *
     * @return array
     */
    protected function getArguments()
    {
        return array();
    }

    /**
     * Get the console command options.
     *
     * @return array
     */
    protected function getOptions()
    {
        return array();
    }

}
  • 写回答

2条回答 默认 最新

  • dqkelut8423 2016-11-23 16:04
    关注

    What is the different between white and green color code ?

    green is for files executable (+x), due to your previous chmod 777

    Why does it place under the dot . ?

    I assume you did a ls -altr wich sort the entries by modification time in ascending order, each time a file is created, the directory inode is modified, so it's listed just before your file (directory modified at file creation, file modified when all text has been written)

    Does it mean anything at all ?

    Well, generally speaking yes, for your error in particular, we have no clue from wich directory you're starting from, if it writes relative to where you are, it's normal you don't find the files.

    Try ls /home/forge/biossantibodies.com/files/product-exports/and if you get an error, cd /home/forge/biossantibodies.com/ and rerun your php command.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改