Monday 15 October 2018

Move large file server to server without downloading file in PHP that will save lot of time






Move large file server to server without downloading file in PHP that will save lot of time




<?php
function moveLargefile($url, $dest)
  {
    $options = array(
      CURLOPT_FILE => is_resource($dest) ? $dest : fopen($dest, 'w'),
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_URL => $url,
      CURLOPT_FAILONERROR => true, // HTTP code > 400 will throw curl error
    );

    $ch = curl_init();
    curl_setopt_array($ch, $options);
    $return = curl_exec($ch);

    if ($return === false)
    {
      return curl_error($ch);
    }
    else
    {
      return true;
    }
  }
 
  echo moveLargefile("http://example.com/blog.zip", "./blog.zip");
?>

Tuesday 28 February 2017

Backup your mysql database with php






backup_tables('localhost','username','password','database_name');

/* backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = '*')
{

$link = mysql_connect($host,$user,$pass);
mysql_select_db($name,$link);

//get all of the tables
if($tables == '*')
{
$tables = array();
$result = mysql_query('SHOW TABLES');
while($row = mysql_fetch_row($result))
{
$tables[] = $row[0];
}
}
else
{
$tables = is_array($tables) ? $tables : explode(',',$tables);
}

//cycle through
foreach($tables as $table)
{
$result = mysql_query('SELECT * FROM '.$table);
$num_fields = mysql_num_fields($result);

$return.= 'DROP TABLE '.$table.';';
$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
$return.= "\n\n".$row2[1].";\n\n";

for ($i = 0; $i < $num_fields; $i++)
{
while($row = mysql_fetch_row($result))
{
$return.= 'INSERT INTO '.$table.' VALUES(';
for($j=0; $j < $num_fields; $j++)
{
$row[$j] = addslashes($row[$j]);
$row[$j] = ereg_replace("\n","\\n",$row[$j]);
if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
if ($j < ($num_fields-1)) { $return.= ','; }
}
$return.= ");\n";
}
}
$return.="\n\n\n";
}

//save file
$handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
fwrite($handle,$return);
fclose($handle);
}





Monday 27 February 2017

How to Install and Enable Multiple Image Upload In Opencart Without Touching Core Files






Enable Multiple Image Upload Without Touching Core Files

Features:
- Upload multiple images to the currently edited product


Opencart Version:
Extension for Opencart 2.0.1.1. But it should also work in other versions of opencart since 2.0 (no

guarantee).

Description
This Opencart extension will save you a lot of time when uploading images in opencart. You can use this

extension to enable multiple images Uploading feature without touching core files.

Demonstration video:


If embed doesn't work visit this link:
https://www.youtube.com/watch?v=-KEUMZZdH_A


Installation
1. In your opencart admin go to "Extensions -> Extension Installer" and upload ocmod xml file

"multi_uploader_image_manager.ocmod.xml" (Note: After successful upload will be"Continue" button disabled.

It's normal.)

2. IMPORTANT: In opencart admin go to "Extensions -> Modifications". Make sure that

multi_uploader_image_manager is enabled and CLICK ON "REFRESH" BLUE BUTTON on the top of the page. It

creates new files in virtual environment. Without this it won't work.

3. That's it. Now Go to filemanager and try to upload multiple.