How to read images from a remote sftp file server - codeigniter

So I'm using CodeIgniter PHP Framework for a website. We have a few servers, a live, a dev, and a file server. We've successfully been able to upload files to our dev server, and then secure copy them to our file server for storage. Our problem now is a way to read/display the images on our dev website from the file server. Our file server uses sftp for it's security. We've been looking into different ways to just pass back an image object from the file server, but not actually the actual file. Any suggestions on how to do this? Thanks.
CodeIgniter PHP Framework
Linux Servers
SFTP on the file server
Thanks...

Well, I have not dealed with sftp so much but at lest I will try to give you some steps to begin.
You need install some apache/php module like ssh2 and enable it with extension=php_ssh2.dll.
You could make your own sftp library, like this:
class Sftp{
protected $connection;
public function __construct($params)
{
}
public function connect()
{
$server = "you-server.com";
$port = "1234";
$username = "admin";
$password = "blabla";
//connect
$ssh2 = ssh2_connect($server, $port);
if(ssh2_auth_password($ssh2, $username, $password))
{
//sftp session
$this->connection = ssh2_sftp($resConnection);
}
else
{
echo "Unable to connect to server";
}
}
public function download($image_name)
{
$image = fopen("ssh2.sftp://{$this->connection}/path/to/{$image_name}", 'r');
fclose($image);
}
}
And then try to use it like:
$this->sftp->connect();
$image = $this->sftp->download('image-name');

I found this Codeigniter library on Github. I haven't used it yet but it seems like you need to do several steps before you could use load the library using Codeigniter. Otherwise this looks promising.
https://github.com/ipolar/CodeIgniter-sFTP-Library

Related

Kreait\Firebase\Exception\Database\DatabaseError 404 Not Found

I am new to Laravel so i have been trying to connect Laravel to a Firebase Realtime database but i am getting this error Kreait\Firebase\Exception\Database\DatabaseError
404 Not Found . I have the Service account in the controllers directory and properly referenced in the Firebase controller.
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Kreait\Firebase;
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
use Kreait\Firebase\Database;
class FirebaseController extends Controller
{
$factory = (new Factory)->withServiceAccount(__DIR__.'/myServiceAccount.json');
$database = $factory->createDatabase();
$newPost = $database->getReference('myrealtime-default-rtdb/blog/posts')->push(['title' => 'Post title','body' => 'This should probably be longer.']);
echo"<pre>";
print_r($newPost->getvalue());
}
}
}
Using the new Factory pattern won't work (it's already handled by the Laravel Service Provider).
Personally I'd recommend using the app() helper. It's quite easy but before that make sure you've followed the installation process in the documentation. You might've missed something
Here's a link to that: https://github.com/kreait/laravel-firebase
Also make sure you include both the path to your Service Account json file and the database URL for your project in your .env file (I prefer using this method personally)
So in your .env file you should have something like
FIREBASE_CREDENTIALS = path_to_your_service_account_file.json
FIREBASE_DATABASE_URL= https://your-project-url.firebaseio.com/
(you can find this url when you open RealTime databases in your firebase console)
If you don't use auto-discovery make sure to add Kreait\Laravel\Firebase\ServiceProvider::class to your providers in the config/app.php file
run a vendor publish
Then in your controller you could have something like this
namespace App\Http\Controllers;
class FirebaseController extends Controller {
//
protected $database;
public function __construct()
{
$this->database = app('firebase.database');
}
public function index(){
$new_post = $this->database->getReference('your-reference')>push(["title" =>"something"]);
} }
Remember: on Linux, place Firebase config files etc. in a folder that user 'apache' can read! So, for example, do not place such files in /home/myname/firebase.json. Even if you do chmod 777 firebase.json, this file may not be accessible by user 'apache', hence the 404.
Then you do not need to use env variables.
$factory = (new Factory())->withServiceAccount(DIR.'/vendor/firebase-adminsdk.json');

Store and download a file from database using laravel

I would like on button press to download a file from database and at the same time to store it on server. There is the used code for download.
$objects = Obj::get()->toArray();
$time = Carbon::now();
$name = "Inventory_Snapshot_".$time;
$export_file = \Excel::create($name, function($excel) use ($objects) {
$excel->sheet("Objects", function($sheet) use ($objects)
{
$sheet->fromArray($objects);
});
});
$export_file->download();
I need somehow to save this file to server too, if the name doesn't exist yet. The path for the stored file has to be public/resources/snap
Thank you!

How to enter localhost url manually ( using xampp php version 7.2)

I am trying to get into my root i have xampp in my D folder and i have create folder name (app) into my htdocs and created file Book.php now i am trying to access this file using url http://localhost/app/Book.php but no output. can anyone correct me?
class Book // class is where we define properties and methods
{
public $isbn;
public $title;
public $author;
public $available;
//instantiate
$harry_potter = new Book();
$harry_potter->isbn = 322401494;
$harry_potter->title = "Harry Potter and Magicians";
$harry_potter->author = "Shahzad";
$harry_potter->available = 10;
var_dump($harry_potter);
Actually, I can see 2 main reasons for this to happen,
You aren't using the right port, XAMPP might be using another port like 8080 check it out in the settings. If this is right then you should access to your file using localhost:port/book.php
Book.php return nothing, you should post book.php code here so we can figure out where is the problem.
Hope it could help.

Joomla 3 test site vs. production site: which files should change?

I am maintaining a Joomla 3 site, and I want to set up a test site in a different web host, so that we can test code changes in it first. The test web host is in a different server, uses a different DB, etc., but otherwise I want it to be as identical as possible to the production site.
Which files should I pay attention to, when downloading and uploading the site to the other host? I know about configuration.php. Is there anything else?
(All the docs I've found when searching were about older versions of Joomla: 1.5, 2.x...)
Here is another solution which does not involve any third party component. You need to take care of some points though. Steps are explained below.
Copy the entire files from 1st server to 2nd server.
From phpmyadmin copy the database from 1st to 2nd server.
Change the database details and other configuration details in the configuration.php file. Mainly you need to change the database details and the log and tmp path. Check the log and tmp folders are writable.
<?php
class JConfig {
public $db = 'joomla';
public $dbprefix = 's5oiy_';
public $log_path = 'C:/xampp/htdocs/joomla/administrator/logs';
public $memcache_server_host = 'localhost';
public $memcache_server_port = '11211';
public $password = 'dbpass';
public $sendmail = '/usr/sbin/sendmail';
public $smtpauth = '0';
public $smtphost = 'localhost';
public $smtppass = '';
public $smtpport = '25';
public $smtpsecure = 'none';
public $smtpuser = '';
public $tmp_path = 'C:/xampp/htdocs/joomla/tmp';
public $user = 'root';
public $memcached_server_host = 'localhost';
public $memcached_server_port = '11211';
public $redis_server_host = 'localhost';
public $redis_server_port = '6379';
public $redis_server_auth = '';
public $redis_server_db = '0';
public $proxy_enable = '0';
public $proxy_host = '';
public $proxy_port = '';
public $proxy_user = '';
public $proxy_pass = '';
public $session_memcache_server_host = 'localhost';
public $session_memcache_server_port = '11211';
public $session_memcached_server_host = 'localhost';
public $session_memcached_server_port = '11211';
}
?>
These are the variables in configuration.php file that need to be checked once you change the server.
If you dont know the Base directory path you may give wrong log and tmp path. So to know the directory path you can use this code
<?php
$dir = getcwd();
echo $dir;
?>
For things like this I suggest using Akeeba Backup and Kickstart
https://www.akeebabackup.com/products/akeeba-backup.html
https://www.akeebabackup.com/products/akeeba-kickstart.html
Just create a backup of your site and use Kickstart to install it on your test server. The install process will take care of the different settings. Make sure you disable sending mails from the test system. Otherwise your users might get mails the should not get.
Sven's suggestion is great, here are a couple of other options.
There might be some advantages to creating your test site on the same server as your production site, for one thing, you'll know that the server environment will be the same. Here are 2 ways you could do this.
You could create a new 'test' subdirectory on your production site and use Akeeba backup to install a copy of your site in that location. If you do this, take care to create a second test database and specify this new database when you use Akeeba backup. When you are finished your production site will be at www.domain.com and your test site will be at www.domain.com/test/
Alternatively StageIt is a very good commercial plugin which will setup a staging environment on your production server. You can test your ideas and sync them back from the test to the production site when you are finished.
Good luck!

how to make working SMTP_validateEmail on live site using php

Not working SMTP_validateEmail on live site using php
https://code.google.com/p/php-smtp-email-validation/
<?php
/**
* Example 1
* Validate a single Email via SMTP
*/
// include SMTP Email Validation Class
require_once('smtp_validateEmail.class.php');
// the email to validate
$email = $_POST['name'];
// an optional sender
$sender = $_POST['name'];
// instantiate the class
$SMTP_Validator = new SMTP_validateEmail();
// turn on debugging if you want to view the SMTP transaction
//$SMTP_Validator->debug = true;
// do the validation
$results = $SMTP_Validator->validate(array($email), $sender);
// send email?
if ($results[$email]) {
echo 1;
} else {
echo 0;
}
enter code here
?>
i am having problem on live site but it works fine in localhost.it shows the print_r($results) in the localhost but shows array(0) result in live.i also find $this->sock value in the class smtp_validateEmail.class function validate(email) value empty in live. how to solve this issue any help will be very thankful.
That "Add your web server ip address to var $nameservers = array(‘192.168.0.1’); and if your web server has Port number then update it here var $port = (Port number); Hope you will get the output by making this changes." Only work if you are sending mail with that script but cant tell if that mail checked is good one or not... I have been testing the code, try all changes, but still cant check other mails outside my domain. I can only make it work on my local and webserver host. Still cant call other servers to check if other mails from outside my domain are valid. Working on it.
Complete downloads are here for others to test : https://code.google.com/p/php-smtp-email-validation/downloads/list
Add your web server ip address to var $nameservers = array(‘192.168.0.1’);
and if your web server has Port number then update it here var $port = (Port number);
Hope you will get the output by making this changes.

Resources