2016-11-23 78 views
0

我有我創建,並作爲bheng用戶無法打開本地文件,但該文件是有

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

該文件導出到我的/files/product-exports/目錄

而且執行的PHP的工匠命令,我已經做了

chmod -R 777 files/product-exports/ 

結果

出口部分工作正常,我得到的文件中導出,你可以在下面

enter image description here 的圖片中看到,但我一直得到這個

enter image description here

什麼是white之間的不同和​​顏色代碼?

爲什麼它放在點.下?

這是否意味着什麼?


問題

這是一些有權限呢?

如何進一步調試?


我打開此時的任何建議。

任何提示/建議/對此的幫助將非常感謝!


更新

由於從要求@Tensibai

CD /home/forge/site.com/ & & PWD & & PHP /家庭/僞造/網站。COM /手工藝品:exportdiff --env =生產

/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

我已經試過dd(file_exists($source));

它不停地回報bool(false)

是因爲我檢查file_exists的方式嗎?


UPDATE3

這裏是我的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(); 
    } 

} 
+0

如您所見,您的文件名以點號 –

+0

結尾,根據屏幕截圖顯示的文件列表不符合。我在想和你一樣的事情。 – ihue

+0

O_o ....你在運行什麼系統? 'pwd'不應該返回'.' ... – Tensibai

回答

2

整個PHP代碼之間是什麼白色和綠色的顏色代碼的不同?

綠色是可執行文件(+ X),由於以前的搭配chmod 777

爲什麼它放置點之下。 ?

我假設你做了一個ls -altr至極排序升序修改時間的條目,每次創建文件時,該目錄inode被修改,所以它只是你的文件(在文件創建修改目錄之前上市,當所有文本被寫入時修改文件)

這是否意味着什麼?

那麼,一般來說是肯定的,尤其是你的錯誤,我們不知道你是從哪個目錄開始的,如果它寫的是你的相對位置,這是正常的,你找不到這些文件。

嘗試ls /home/forge/biossantibodies.com/files/product-exports/,如果您收到錯誤,cd /home/forge/biossantibodies.com/並重新運行您的php命令。

+0

我試過'ls/home/forge/biossantibodies.com/files/product-exports /'我看到很多文件都列好了。 我試過'php /home/forge/biossantibodies.com/artisan產品:exportdiff --env = production',如同建議的那樣,我再次得到同樣的錯誤'無法打開本地文件:/ home/forge/biossantibodies/files /產品出口/ export1084_2016-11-23.csv.' ... OMG這是如此煩人。 – ihue

+0

@ihue你可以試試'cd /home/forge/biossantibodies.com/ && pwd && php /home/forge/biossantibodies.com/artisan產品:exportdiff --env = production'並在你的問題中發佈控制檯輸出到確保發生了什麼? – Tensibai

+0

我試過了你的命令,並根據請求在我的文章中添加了控制檯輸出。 – ihue

1
  • 可執行文件:綠色
  • 目錄:
  • 圖像文件(JPG,GIF,BMP,PNG,TIF):品紅
  • 符號鏈接:青色
  • 管道:
  • 插座:品紅
  • 孤立的符號鏈接:閃爍大膽的白色和紅色 背景
  • 塊設備驅動程序:鮮黃色的前景,用黑色 背景
  • 缺少鏈接以及它們指向的文件:閃爍加粗的白色 與紅色背景
  • 檔案或壓縮文件(如焦油,GZ,ZIP,RPM):
  • 目錄已在鏈接到自身。進入
  • 它的每一個子目錄中有一個鏈接通過回..

    因此,它似乎並沒有什麼特別的事情與文件的權限,請檢查您正在訪問文件或共享代碼的方式。
+0

我用我的整個PHP更新了我的帖子。你可以看一下嗎? – ihue

+0

我發現問題的人,你是對的。它在代碼中。 – ihue

+0

聽起來很棒,您的問題已解決。 – DnA