Laravel SQL server connection - laravel

I have laravel 7.3, and sql server 16,
i need to connect to the database sql server, but i have this error :
SQLSTATE = 08001 error- No connection could be made because the target machine actively refused it.
and there is the .env file
DB_CONNECTION=sqlsrv
DB_HOST=127.0.0.1/instancename
DB_PORT=1433
DB_DATABASE=Database
DB_USERNAME=sa
DB_PASSWORD=12345678`
But when i use the simple php file to connect the connexion is ok.
this is the php script :
<?php
$serverName = "127.0.0.1/instancename";
$connectionInfo = array( "Database"=>"Database", "UID"=>"sa", "PWD"=>"12345678");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connexion établie.<br />";
}else{
echo "La connexion n'a pu être établie.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
Manny thanks for your help

Related

Secure FTP file download

I'm trying to download the most recent file with the extension add.zip via ftp
I'll preface this by saying I am not well versed in php and have created this frankenstein piece of code from a scattering of other codes.
here is my code
<?php
// set up basic ssl connection
$ftp = ftp_ssl_connect('myremotesite.com');
// login with username and password
$login_result = ftp_login($ftp, 'username', 'password');
if (!$login_result) {
// PHP will already have raised an E_WARNING level message in this case
die("can't login");
}
// get list of files on given path
$files = ftp_nlist($ftp, '/1668161919_DATA/*add.zip') or die("Could not find file");
$mostRecent = array(
'time' => 0,
'file' => null
);
foreach ($files as $file) {
// get the last modified time for the file
$time = ftp_mdtm($ftp, $file);
if ($time > $mostRecent['time']) {
// this file is the most recent so far
$mostRecent['time'] = $time;
$mostRecent['file'] = $file;
}
}
ftp_get($ftp, "/home/mysite/public_html/wp-content/uploads/data-zipped/target.zip", $mostRecent['file'], FTP_BINARY);
ftp_delete($ftp, $mostRecent['file']);
ftp_close($ftp);
?>
After some testing
<?php
// set up basic ssl connection
$ftp = ftp_ssl_connect('myremotesite.com');
// login with username and password
$login_result = ftp_login($ftp, 'username', 'password');
if ($login_result === TRUE) {
echo 'woot!';
} else {
echo 'doh!';
}
Returns a woot
but
// set up basic ssl connection
$ftp = ftp_ssl_connect('myremotesite.com');
// login with username and password
$login_result = ftp_login($ftp, 'username', 'password');
// get list of files on given path
$files = ftp_nlist($ftp, '/1668161919_DATA/*add.zip');
if ($files === TRUE) {
echo 'files found!';
} else {
echo 'doh! files not found';
}
?>
Cause a 504 error with no further information.
What am I doing wrong?
When I copy the URL to clipboard in FileZilla the data is sftp://username#myremotesite.com/1668161919_DATA
Am I even close to getting this right?
When I have tried using similar FTP file downloads in the past, it was with
ftp_connect
This is the first time I have been forced to use
ftp_ssl_connect
Ok, so I set up a testing environment and ran the script using ftp_connect instead of ftp_ssl_connect and the code worked fine.
I think I need to define my port as 22. But
$ftp = ftp_ssl_connect('myremotesite.com','22')
doesn't work. Can anyone assist?

Laravel ClamAV scanner client failed with error "Socket operation failed: Connection refused

I have created a validation system to check if the uploaded files are secured and virus-free, I'm using ClamAV for that purpose.
At first I was testing locally on my MACOS using XAMPP but I kept getting the below error
Sunspikes \ ClamavValidator \ ClamavValidatorException ClamAV scanner
client failed with error "Socket operation failed: Connection refused
(SOCKET_ECONNREFUSED)" Previous exceptions Socket operation failed:
Connection refused (SOCKET_ECONNREFUSED) (61)
I've uploaded the files to my cPanel/CentOS server thought that clamav is limited on MacOS unlike CentOS however I got the same error.
The code used as follow:
public function upload(KycUploadRequest $request) {
$this->validate($request, [
'address' => 'clamav',
'document' => 'clamav'
]
);
//
$user = Auth::user();
$data = $request->all();
if($file = $request->file('address')) {
$name = time() . $file->getClientOriginalName();
$file->move('images', $name);
$data['address'] = $name;
}
if($file2 = $request->file('document')) {
$name = time() . $file2->getClientOriginalName();
$file2->move('images', $name);
$data['document'] = $name;
}
$kyc = new KycVerification();
$kyc->user_id = $user->id;
$kyc->address = $data['address'];
$kyc->document = $data['document'];
$kyc->status = 1;
$kyc->save();
Session::flash('status', 'Your documents were sent for verification, you will receive a notification status about your request!');
return redirect()->back();
}
I use this package: https://github.com/sunspikes/clamav-validator
I'm stuck for hours with no solution, any help please. Note I'm using laravel 5.8 both on xampp/macos and cpanel/centos.

Swift_TransportException email does not work laravel

When I run this
<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "xyssoftware#gmail.com";
$to = $from;
$subject = "PHP Mail Test script";
$message = "This is a test to check the PHP Mail functionality";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
echo "Test email sent";
?>
page email works.
But when I hit my mail::send method it runs to this error:
Swift_TransportException in StreamBuffer.php line 268: Connection
could not be established with host mailtrap.io [Connection refused
#111]
IF you are sending an email from your webserver and have sendmail and postfix installed.
Then you have to change your email driver from your .env to MAIL_DRIVER=mail
MAIL_DRIVER=mail
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
if u are in development then you can simply change the driver to log.
MAIL_DRIVER=log
Hope this helps

PHP code not working on ipage hosting?

My code is working well on localhost and also on godaddy server.But on ipage I am getting "500 Internal Server error" with this code.
My local server has PHP Version 5.4.7 and my ipage hosting has PHP Version 5.3.13
public function cms($cid,$vars) {
global $db;
//fetch cms data from database
$stmt = $db->prepare("SELECT * FROM cms");
$stmt->execute();
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $row;
if ($cid == ""){
$stmt = $db->prepare("SELECT * FROM cms");
$stmt->execute();
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $row;
}
else {
$stmt = $db->prepare("SELECT * FROM cms WHERE id=? ");
$stmt->execute(array($cid));
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($vars == "") {
return $row;
}
else {
$ret = [];
foreach ($vars as $var) {
$ret[] = [
$var => $row[0][$var]
];
}
return $ret;
}
}
}
I think its version problem and for that you need to ask your hosting provider(ipage) to make your php version same as your local version..
Also check out your .htaccess file too, cos. some time redirection can also give this types of error.
if anyone facing internal server (500) error in ipage, you can chat or call them, then they will upgrade your version to 7 or above.
you can check your php version using this code.
<?php
phpinfo();
?>

Check if a file exist on remote server and save th url path in a magento attribute

Hi im trying to check if a file exist on a remote server and then save the url path to the file in a attribute on the product in magento.
This is how far i have got . i use some code from another function i have that imports images to my magento store. But i have never tested to only get the url path .
<?php
ini_set('display_errors', 1);
require_once('app/Mage.php');
Mage::app();
$_productCollection = Mage::getModel('catalog/product')->getCollection();
$url = "http://www.imonline.se/media42/trailers/199151abe/swinks/hkmedia/";
foreach($_productCollection as $product)
{
//if(file_exists($serverurl))
{
$thispro = Mage::getModel('catalog/product')->load($product->getId());
$attributeValue = $thispro->getFaktaId();
$imgupdate = $thispro->getImgupdate();
if($thispro->getFaktaId()=="" || $thispro->getImage()=="no_selection")
{
if($attributeValue != "")
{
copy($url.$attributeValue );
$im = $attributeValue.".mp4";
if(file_exists)
{
$product->setFilmUrl($url.$im);
$product->save();
}
}
}
}
}
?>
file_exists - Checks whether a file or directory exists
To Check if Remote File Exists using PHP
$url = $url.$im;
$exist = file_exists_remote($url);
if($exist) {
echo 'File Exists';
$product->setFileUrl($url.$im);
$product->save();
} else {
echo 'File not found';
}

Resources