无法打开本地文件,但文件在那里
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
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();
}
}
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.
- Executable files: Green
- Directory: Blue
- Image files(jpg, gif, bmp, png, tif): Magenta
- Symbolic links: Cyan
- Pipe: Yellow
- Socket: Magenta
- Orphaned symbolic links: Blinking Bold white with red
background
- Block device driver: Bold yellow foreground, with black
background
- Missing links along with files they point to: Blinking Bold white
with red background
- Archives or compressed files(like tar,gz,zip,rpm): Red
- The directory has a link to itself in the . entry
- Each of its sub-directories has a link back via ..
So it doesn't seem anything special with the file permission please check the way you are accessing the file or share code.