ZipArchive::extractTo doesn't working on Windows Platform - ziparchive

I'm using the following code (Windows Hosting - Plesk/Win) :
<?php
$zip = new ZipArchive;
$res = $zip->open('file.zip');
if ($res === TRUE) {
$path = getcwd();
$path = str_replace("/","\\",$path);
echo $path;
$zip->extractTo('E:\\Vhosts\\domain.com\\httpdocs\\test\\');
$zip->close();
echo 'Ok!';
} else {
echo 'Error!';
}
?>
When I run this code, the following message appears:
Warning:
ZipArchive::extractTo(E:\Vhosts\domain.com\httpdocs\test/image1.jpg)
[ziparchive.extractto]: failed to open stream: Permission denied in
E:\Vhosts\domain.com\httpdocs\test\extractphp.php on line 10
I don't now why this command put a slash before the unzipped file (test/image1.jpg).
How can I resolve this issue ?

Related

Copy logs file to another path laravel

I want to get a copy of the logs file using programmability, I just tried to copy the files using this command
$co= Storage::copy('logs/laravel-'.$start.'.log',$filename);
dd($co);
but I have an error which says the file does not exist,
I believe that is because storage looking in the default driver of the config file, how can I tell laravel to look in logs folder when I want to run the copy command, is there any way to do that .
Hi You can get the path of the log file with storage_path() and copy your file anywhere you want with php copy function
I think that is a easy way that you can do it:
<?php
function copyLogFile($logFileName, $destination)
{
$logPathDir = storage_path().'/logs/';
$logFilePath = $logPathDir . $logFileName;
if (file_exists($logFilePath)) {
if( !#copy($logFilePath, $destination) ) {
echo "File can't be copied! \n";
$errors= error_get_last();
echo "COPY ERROR TYPE: ".$errors['type'].PHP_EOL;
echo "COPY ERROR MESSAGE: ".$errors['message'];
}
else {
echo "File has been copied! \n";
}
} else {
echo "The file $logFilePath does not exist";
}
}
// Store the path of destination file
$destination = '/home/azibom/Desktop/backup.log';
// Your log file name
$start = "2020-01-01";
$logFileName = 'laravel-'.$start.'.log';
copyLogFile($logFileName, $destination);
?>

How can I show up the errors in Laravel when response is 500?

I have a Laravel application working on different urls. example.ch and app.example.net are working will. On the same server like app.example.net i like to run app-stage.example.net.
The application return an error 500 without an error log.
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
var_dump($kernel); // returns an object. Everything ok
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
var_dump($response) //returns error 500
I checked the php version.
I checked the fpm version.
I checked the .env file
I did "sudo chmod -R 777 bootstrap/cache storage"
I restarted the server.
I tried to show the errors.
error_reporting(-1); // reports all errors
ini_set("display_errors", "1"); // shows all errors
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
No success.
What can I do in addition to find the error?
use this package Dotenv
make a file like this
and then use multiple .env for example acceptnace.env . production.env , staging.env
make a file like environment.php in bootstrap directory like this
<?php
$envPath = realpath(dirname(__DIR__));
$env = get_current_user();
if ($env == 'staging') {
$envFile = ".staging.env";
} elseif ($env == "acceptance") {
$envFile = ".acceptance.env";
} elseif ($env == "development") {
$envFile = ".development.env";
} elseif ($env == "production") {
$envFile = ".production.env";
} elseif ($env == "beta") {
$envFile = ".beta.env";
} else {
$envFile = ".local.env";
}
Dotenv\Dotenv::create($envPath, $envFile)->load();
and this will load multiple env for your app

tsung_stats.pl on Mac OS X Mavericks run into "Can't locate Template.pm" error

I'm trying to run tsung_stats.pl from tsung (installed through brew) on Mac OS X 10.9 and got error:
Can't locate Template.pm in #INC (#INC contains:
/Library/Perl/5.16/darwin-thread-multi-2level /Library/Perl/5.16
/Network/Library/Perl/5.16/darwin-thread-multi-2level
/Network/Library/Perl/5.16 /Library/Perl/Updates/5.16.2
/System/Library/Perl/5.16/darwin-thread-multi-2level
/System/Library/Perl/5.16
/System/Library/Perl/Extras/5.16/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.16 .) at tsung_stats.pl line 564
I searched and it seems I have to install perl templates, so I ran "sudo cpan Template" and yet still get the same error.
cpan and perl are all in /usr/bin/. Tsung is in /usr/local/Cellar/tsung/1.5.0/bin/tsung
Versions are:
perl: perl 5, version 16, subversion 2 (v5.16.2)
cpan: 1.57
tsung: 1.5.0
I searched my system and found no file name Template.pm. The closest I found was two TextTemplate.pm files in
/System/Library/Perl/Extras/5.16/Locale/Maketext/Extract/Plugin/
/System/Library/Perl/Extras/5.12/Locale/Maketext/Extract/Plugin/
The following code snippet in question starts from line 563:
sub html_report {
require Template;
my $titre = 'Tsung ';
my $version = $tagvsn;
my $contact = 'tsung-users#process-one.net';
my $output = 'index.html';
my $tt = Template->new({
INCLUDE_PATH => $template_dir,
PRE_CHOMP => 1,
INTERPOLATE => 1,
}) or die "Template error " . Template->error();
my $xml_conf;
opendir (DIR, ".") or warn "can't open directory .";
while (my $file = readdir (DIR) ) {
if ($file =~ /.xml$/) {
$xml_conf= $file;
}
}
foreach my $type ("mean", "maxmean", "minmean") {
foreach my $data (keys % {$maxval->{$type}} ) {
next if ($data =~ m/^size/);
if ($data =~ m/os_mon/) {
$maxval->{$type}->{$data} = sprintf "%.2f",$maxval->{$type}->{$data};
next;
}
next if not ($data eq "session" or $data eq "connect" or $data eq "request" or $data eq "page" or $data =~ m/^tr_/);
$maxval->{$type}->{$data} = &formattime($maxval->{$type}->{$data});
}
}
foreach my $size ("size_rcv", "size_sent") {
if ($maxval->{rate}->{$size}) {
$maxval->{rate}->{$size} = &formatsize($maxval->{rate}->{$size}*8,"bits");
$maxval->{maxmean}->{$size} = &formatsize($maxval->{maxmean}->{$size},"B");
} else {
warn "$size is equal to 0 !\n";
}
}
my $vars =
{
version => $version,
os_mon => $extra,
errors => $errors,
title => $titre,
subtitle => "Stats Report",
http => $http,
stats_subtitle => "Stats Report ",
graph_subtitle => "Graphs Report ",
contact => $contact,
data => $maxval,
cat_data => $category,
conf => $xml_conf
};
$tt->process("report.thtml", $vars, "report.html") or die $tt->error(), "\n";
$vars =
{
version => $version,
os_mon => $extra,
errors => $errors,
http => $http,
match => $match,
async => $async,
bosh => $bosh,
title => $titre,
subtitle => "Graphs Report",
stats_subtitle => "Stats Report ",
graph_subtitle => "Graphs Report ",
os_mon_other=> $os_mon_other,
contact => $contact,
conf => $xml_conf,
ext => $imgfmt
};
if (not $dygraph) {
$tt->process("graph.thtml", $vars, "graph.html") or die $tt->error(), "\n";
} else {
$tt->process("graph_dy.thtml", $vars, "graph.html") or die $tt->error(), "\n";
copy (($template_dir . "/dygraph-combined.js"), ".") or die "copy failed : $!";
}
}
I believe $template_dir is in this piece of code (start from line 71):
my $prefix ="/usr/local/Cellar/tsung/1.5.0";
unless ($template_dir) {
if (-d (dirname($0) . "/templates/")) {
$template_dir = dirname($0)."/templates/";
} elsif (-d "$ENV{HOME}/.tsung/templates/") {
$template_dir = "$ENV{HOME}/.tsung/templates/";
} elsif (-d "${prefix}/share/tsung/templates") {
$template_dir = "${prefix}/share/tsung/templates";
} elsif (-d "/usr/share/tsung/templates") {
$template_dir = "/usr/share/tsung/templates";
} elsif (-d "/usr/local/share/tsung/templates") {
$template_dir = "/usr/local/share/tsung/templates";
} else {
warn "Can't find template directory !";
}
}
I checked those locations and found some .pm files, but none were Template.pm.
Any help would be appreciated.
As deduced in the comments:
You need to install Template::Toolkit.
For tsung >= 1.6 and perl 5:
sudo cpan Template
just (on windows) run the following lines on cmd
cd C:\Perl64\bin
ppm install Template-Toolkit
If you tried by running cpan Template or cpan Template:Toolkit and still have this issue, check the version number and the path.
The file: tsung_stats.pl is using /usr/bin/perl and if for some reason you have another perl (like me) in /usr/local/Cellar/perl chances are the script never finds the Template you just installed.
Modify the file tsung_stats.pl in the first line from:
#!/usr/bin/perl -w
to
#!/usr/bin/env perl -w
This will load your perl version used by cpan.

Magento Index Management issues, products not displaying in category pages

This is a Magento issue - using the Enterprise edition. Unfortunately their support technicians are all in San Francisco, and I am based in the UK, so their support to me is restricted to a certain time window.
I have categories which are active, set to display products, and/or products and static blocks, and are sub categories of the default root category.
I also have test products, which are enabled, in stock, with quantities, visible in Catalog, Search, and are assigned to these sub categories.
The problem is, my test products (or any product!) do not show on the category page. I am using the default/default themes, and have not changed the page_layout.
I have cleared/flushed all caches, and reindexed.
However, most of my indexes appear as status 'SCHEDULED' and have never been updated - there are no checkboxes next to these, so I cannot select them to 'reindex data'.
See the screenshot.
If anyone has any clues on how to fix this, I will be very happy.
Thanks
Reindex is somewhat required to display products on front, especially if you have flat tables enabled (Admin Panel > System > Configuration > Catalog > Frontend: "Use Flat Catalog Category" and "Use Flat Catalog Product").
The situation with indexes is a bit of strange. It you do it on your local workstation or you have access to shell on hosting you can manually force indexes by running this command:
pwd$ php shell/indexer.php reindexall
If you have enabled flat tables you can try to disable them, to check if products will be visible on front.
You need to also put right permissions on var and media folders and theirs content. 755 should be ok.
Problem solved. Thanks guys for your answers but it was none of the above.
I had installed a Product Feature module incorrectly. I was under the assumption that when developing in app/code/local/... anything that didn't work would fall back to app/code/core/...
Sadly this was not the case. My fault, and everyone knows the phrase about making assumptions.
Magento has a very steep learning curve!
Thats really interesting, I had a similar issue recently where a reindex was not fully working. However I didnt get scheduled being displayed.
Can I ask what version of Enterprise are you using ?
As Ventus suggested a tried and tested method of forcing a reindex is to use the shell script, To do this you need to SSH into your server. Then use the cd command ( change directory ) to where your website is located on the file system. E.g. cd /var/www/....
From here run php shell/indexer.php reindexall
Set cron to run this will take care of reindexing provided you have not changed crontab values.
From your screen it looks like you have never run a cron on this setup.
Put this code below into a .php file in your magento install and then run it from your URL, this will clean and re-index everything. You can run it from a cron job. Any errors then you have a problem with yor database in witch case you should back it up and then re-creat it in a new DB instance.
<?php
set_time_limit(0);
require_once dirname(__FILE__) . '/app/Mage.php';
//get all stores
$websites = Mage::app()->getWebsites();
$thisstore = $websites[1]->getDefaultStore()->getCode();
echo "Store: ".$thisstore."<br/>";
//clean var dir
$dirs = array(
'downloader/.cache/*',
'var/cache/',
'var/locks/',
'var/log/',
'var/report/',
'var/minifycache/',
'var/mincache/',
'var/tmp/'
);
foreach($dirs as $v => $k) {
exec('rm -rf '.$k);
}
/*
//clean out sessions
$dirs = array('var/session/');
foreach($dirs as $v => $k) {
exec('rm -rf '.$k);
}
*/
//clean db log files
$xml = simplexml_load_file('./app/etc/local.xml', NULL, LIBXML_NOCDATA);
$db['host'] = $xml->global->resources->default_setup->connection->host;
$db['name'] = $xml->global->resources->default_setup->connection->dbname;
$db['user'] = $xml->global->resources->default_setup->connection->username;
$db['pass'] = $xml->global->resources->default_setup->connection->password;
$db['pref'] = $xml->global->resources->db->table_prefix;
global $db;
$tables = array(
'catalogsearch_fulltext',
'dataflow_batch_export',
'dataflow_batch_import',
'log_customer',
'log_quote',
'log_summary',
'log_summary_type',
'log_url',
'log_url_info',
'log_visitor',
'log_visitor_info',
'log_visitor_online',
'importexport_importdata',
'core_url_rewrite',
'report_viewed_product_index',
'report_event',
'core_cache',
'core_cache_option',
'core_cache_tag'
);
mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
mysql_select_db($db['name']) or die(mysql_error());
foreach($tables as $v => $k) {
mysql_query('SET FOREIGN_KEY_CHECKS=0; '.'TRUNCATE `'.$db['pref'].$k.'`;'.' SET FOREIGN_KEY_CHECKS=1; ') or die(mysql_error());
}
///---------------------------------//
// now run standard magento cleanup file
## Function to set file permissions to 0644 and folder permissions to 0755
function AllDirChmod( $dir = "./", $dirModes = 0755, $fileModes = 0644 ){
$d = new RecursiveDirectoryIterator( $dir );
foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){
if( $path->isDir() ) chmod( $path, $dirModes );
else if( is_file( $path ) ) chmod( $path, $fileModes );
}
}
## Function to clean out the contents of specified directory
function cleandir($dir) {
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..' && is_file($dir.'/'.$file)) {
if (unlink($dir.'/'.$file)) { }
else { echo $dir . '/' . $file . ' (file) NOT deleted!<br />'; }
}
else if ($file != '.' && $file != '..' && is_dir($dir.'/'.$file)) {
cleandir($dir.'/'.$file);
if (rmdir($dir.'/'.$file)) { }
else { echo $dir . '/' . $file . ' (directory) NOT deleted!<br />'; }
}
}
closedir($handle);
}
}
function isDirEmpty($dir){
return (($files = #scandir($dir)) && count($files) <= 2);
}
// rebuild everything!!!
$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_REAL_TIME));
$processes->walk('save');
$processes->walk('reindexAll');
$processes->walk('reindexEverything');
echo "----------------------- CLEANUP START -------------------------<br/>";
$start = (float) array_sum(explode(' ',microtime()));
echo "<br/>*************** SETTING PERMISSIONS ***************<br/>";
echo "Setting all folder permissions to 755<br/>";
echo "Setting all file permissions to 644<br/>";
AllDirChmod( "." );
echo "Setting pear permissions to 550<br/>";
echo "<br/>****************** CLEARING CACHE ******************<br/>";
if (file_exists("var/cache")) {
echo "Clearing var/cache<br/>";
cleandir("var/cache");
}
if (file_exists("var/session")) {
echo "Clearing var/session<br/>";
cleandir("var/session");
}
if (file_exists("var/minifycache")) {
echo "Clearing var/minifycache<br/>";
cleandir("var/minifycache");
}
if (file_exists("downloader/pearlib/cache")) {
echo "Clearing downloader/pearlib/cache<br/>";
cleandir("downloader/pearlib/cache");
}
if (file_exists("downloader/pearlib/download")) {
echo "Clearing downloader/pearlib/download<br/>";
cleandir("downloader/pearlib/download");
}
if (file_exists("downloader/pearlib/pear.ini")) {
echo "Removing downloader/pearlib/pear.ini<br/>";
unlink ("downloader/pearlib/pear.ini");
}
if (file_exists("media/catalog/product/cache/")) {
echo "Removing media/catalog/product/cache/<br/>";
unlink ("media/catalog/product/cache/");
}
if (file_exists("media/tmp/")) {
echo "Removing media/tmp/<br/>";
unlink ("media/tmp/");
}
date_default_timezone_set("Europe/London");
echo "Start Cleaning all caches at ... " . date("Y-m-d H:i:s") . "<br/>";
ini_set("display_errors", 1);
Mage::app('admin')->setUseSessionInUrl(false);
Mage::getConfig()->init();
$types = Mage::app()->getCacheInstance()->getTypes();
try {
echo "Cleaning data cache... <br/>";
flush();
foreach ($types as $type => $data) {
echo "Removing $type ... ";
echo Mage::app()->getCacheInstance()->clean($data["tags"]) ? "[OK]" : "[ERROR]";
echo "<br/>";
}
} catch (exception $e) {
die("[ERROR:" . $e->getMessage() . "]");
}
echo "<br/>";
try {
echo "Cleaning stored cache... ";
flush();
echo Mage::app()->getCacheInstance()->clean() ? "[OK]" : "[ERROR]";
echo "<br/>";
} catch (exception $e) {
die("[ERROR:" . $e->getMessage() . "]");
}
try {
echo "Cleaning merged JS/CSS...";
flush();
Mage::getModel('core/design_package')->cleanMergedJsCss();
Mage::dispatchEvent('clean_media_cache_after');
echo "[OK]<br/>";
} catch (Exception $e) {
die("[ERROR:" . $e->getMessage() . "]");
}
try {
echo "Cleaning image cache... ";
flush();
echo Mage::getModel('catalog/product_image')->clearCache();
echo "[OK]<br/>";
} catch (exception $e) {
die("[ERROR:" . $e->getMessage() . "]");
}
echo "<br/>************** CHECKING FOR EXTENSIONS ***********<br/>";
If (!isDirEmpty("app/code/local/")) {
echo "-= WARNING =- Overrides or extensions exist in the app/code/local folder<br/>";
}
If (!isDirEmpty("app/code/community/")) {
echo "-= WARNING =- Overrides or extensions exist in the app/code/community folder<br/>";
}
$end = (float) array_sum(explode(' ',microtime()));
echo "<br/>------------------- CLEANUP COMPLETED in:". sprintf("%.4f", ($end-$start))." seconds ------------------<br/>";
//sitemap refresh
$collection = Mage::getModel('sitemap/sitemap')->getCollection();
foreach ($collection as $sitemap) {
try {
$sitemap->generateXml();
}
catch (Exception $e) {
$errors[] = $e->getMessage();
}
}
?>

NuSOAP on XAMPP with PHP5: failed to open stream

Hey guys, I have a problem (again). This time I am trying to use NuSoap w/ XAMPP 1.7.1 which includes PHP5 and MySQL ... I wrote a soap-client:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the client instance
$client = new soapclient('http://localhost/mysql/helloworld2.php');
// Check for an error
$err = $client->getError();
if ($err) {
// Display the error
echo '<p><b>Constructor error: ' . $err . '</b></p>';
// At this point, you know the call that follows will fail
}
// Call the SOAP method
$result = $client->call('hello', array('name' => 'Doro'));
// Check for a fault
if ($client->fault) {
echo '<p><b>Fault: ';
print_r($result);
echo '</b></p>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<p><b>Error: ' . $err . '</b></p>';
} else {
// Display the result
print_r($result);
}
}
?>
and my soap-server:
// Enable debugging *before* creating server instance
$debug = 1;
// Create the server instance
$server = new soap_server;
// Register the method to expose
$server->register('hello');
// Define the method as a PHP function
function hello($name) {
$dbhost = 'blah';
$dbuser = 'blub';
$dbpass = 'booboo';
try{
$conn = MYSQL_CONNECT($dbhost, $dbuser, $dbpass)
or die ('Error connecting to mysql');
if( !$conn ){
return 'Hello, '.$name.' ... too bad, I cannot connect to the db!';
}
else{
$dbname = 'soaperina';
MYSQL_SELECT_DB($dbname) or die('Error connecting to '.dbname);
$queryres = #mysql_db_query(
'response',
'SELECT * FROM farben');
return 'RESPONSE: <br>';
while( $arr = mysql_fetch_array( $queryres ) ){
return $arr["ID"]." - ".$arr["Farben"]." - ".$arr["Rating"]."<br>";
}
}
}
catch(Exception $e){
return 'Sorry, '.$name.', but that did not work at all!';
}
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
I know that PHP works, the Apache works, MySQL works ... it also works together, but when I try to make it work with NuSOAP it does not work. I get following:
Warning:
SoapClient::SoapClient(http://localhost/mysql/helloworld2.php)
[soapclient.soapclient]: failed to
open stream: Ein Verbindungsversuch
ist fehlgeschlagen, da die Gegenstelle
nach einer bestimmten Zeitspanne nicht
richtig reagiert hat, oder die
hergestellte Verbindung war
fehlerhaft, da der verbundene Host
nicht reagiert hat. in
C:\xampp\htdocs\mysql\helloworld2client.php
on line 6
Warning: SoapClient::SoapClient()
[soapclient.soapclient]: I/O warning :
failed to load external entity
"http://localhost/mysql/helloworld2.php"
in
C:\xampp\htdocs\mysql\helloworld2client.php
on line 6
Fatal error: Maximum execution time of
60 seconds exceeded in
C:\xampp\htdocs\mysql\helloworld2client.php
on line 41
I have no idea what that is supposed to mean. I hope ya'll can help!!! Thnx in advance :)
I used NuSOAP version 1.7.3 with PHP5. In this NuSOAP 1.7.3, soapclient class renamed by nu_soapclient.
You can try this:
$client = new nusoap_client('http://localhost/mysql/helloworld2.php');
to give an answer to my own question: nusoap has a problem with php5 ... there are some answers and some solutions on the net (not many), but they didn't work with me. I downgraded to php4 and it works fine ...

Resources