23 if (is_array($value))
return (
sizeof($value) > 0)?
true :
false;
24 else return (($value !=
'') && (strtolower($value) !=
'null') && (strlen(trim($value)) > 0)) ?
true :
false;
31 $mail_attached.=
"--".$boundary.$newline
32 .
"Content-Type: application/octet-stream;$newline name=\"$file_name\"$newline"
33 .
"Content-Transfer-Encoding: base64$newline"
34 .
"Content-Disposition: attachment;$newline filename=\"$file_name\"$newline$newline"
35 .chunk_split(base64_encode($content)).$newline;
36 $mail_attached .=
"--".$boundary.
"--$newline";
37 $add_header =
"MIME-Version: 1.0".$newline.
"Content-Type: multipart/mixed;$newline boundary=\"$boundary\" $newline";
38 $mail_content=
"--".$boundary.$newline.
"Content-Type: text/plain; $newline charset=\"iso-8859-1\"$newline".
"Content-Transfer-Encoding: 7bit$newline $newline BACKUP Successful...$newline $newline Please see attached for your zipped Backup file; $backup_type $newline If this is the first backup then you should test it restores correctly to a test server.$newline $newline phpMySQLAutoBackup (version $ver) is developed by http://www.dwalker.co.uk/ $newline $newline Have a good day now you have a backup of your MySQL db :-) $newline $newline Please consider making a donation at: $newline http://www.dwalker.co.uk/make_a_donation.php $newline (every penny or cent helps)$newline".$mail_attached;
48 if (!file_exists(
LOCATION.
"../backups/.htaccess"))
50 $fp = fopen(
LOCATION.
"../backups/.htaccess",
"w");
51 fwrite($fp,
"deny from all");
60 $prefix =
'mysql_'.DBNAME;
63 if ($handle = opendir($dir))
65 while (
false !== ($file = readdir($handle)))
67 if ((filetype($dir.$file) ==
"file") && (substr($file,0,strlen($prefix)) == $prefix) && (substr($file,-strlen($suffix)) == $suffix) && (filesize($dir.$file)>0))
69 $files[filemtime($dir.$file)]= $file;
78 foreach ($erase as $key=>$thisOne)
80 unlink($dir.$thisOne);
91 public function transfer_data($ftp_username,$ftp_password,$ftp_server,$ftp_path,$filename)
93 if (function_exists(
'curl_exec'))
95 $file=
LOCATION.
"../backups/".$filename;
96 $fp = fopen($file,
"r");
98 curl_setopt($ch, CURLOPT_URL,
"ftp://$ftp_username:$ftp_password@$ftp_server.$ftp_path".$filename);
99 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
100 curl_setopt($ch, CURLOPT_UPLOAD, 1);
101 curl_setopt($ch, CURLOPT_INFILE, $fp);
102 curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file));
103 curl_setopt($ch, CURLOPT_TRANSFERTEXT, 0);
104 curl_setopt($ch, CURLOPT_REFERER, $_SERVER[
'HTTP_HOST'].
" - via phpMySQLAutoBackup");
105 $output = curl_exec($ch);
106 $info = curl_getinfo($ch);
107 if (empty($info[
'http_code'])) $this->error =
"\n\nFTP ERROR - Failed to transfer backup file to remote ftp server";
110 $http_codes = parse_ini_file(
LOCATION.
"http_codes.ini");
111 if ($info[
'http_code']!=226) $this->error =
"\n\nFTP ERROR - server response: \n".$info[
'http_code']
112 .
" " . $http_codes[$info[
'http_code']]
113 .
"\nfor more detail please refer to: http://www.w3.org/Protocols/rfc959/4_FileTransfer.html" ;
118 else $this->error =
"\n\nWARNING: FTP will not function as PHP CURL does not exist on your hosting account - try a new host: http://www.seiretto.com";
126 public function save($date, $bytes, $lines)
129 $result =
$dbc->prepare(
"SHOW TABLES LIKE 'phpmysqlautobackup_log' ");
133 $q=
"CREATE TABLE IF NOT EXISTS `phpmysqlautobackup_log` (
134 `date` int(11) NOT NULL,
135 `bytes` int(11) NOT NULL,
136 `lines` int(11) NOT NULL,
137 PRIMARY KEY (`date`) )";
141 $query=
"INSERT INTO `phpmysqlautobackup_log` (`date`, `bytes`, `lines`)
142 VALUES ('$date', '$bytes', '$lines')";
145 $query=
"SELECT date FROM `phpmysqlautobackup_log` ORDER BY `date` DESC LIMIT 0 , ".LOG_REPORTS_MAX;
150 $query=
"delete FROM `phpmysqlautobackup_log` where date<'$search_date' ";
155 public function get()
158 $result =
$dbc->prepare(
"SELECT * FROM `phpmysqlautobackup_log` ORDER BY `date` DESC ");
160 $report=
"\nBelow are the records of the last ".LOG_REPORTS_MAX.
" backups.\nDATE and TIME (total bytes, Total lines exported)";
161 foreach (
$rows as $row)
163 $report.=
"\n".strftime(
"%d %b %Y - %H:%M:%S",$row[
'date']).
" (";
164 $report.= number_format(($row[
'bytes']/1000), 2,
'.',
'') .
" KB, ";
165 $report.= number_format($row[
'lines']).
" lines)";
176 $newest_version=$version;
177 if (function_exists(
'curl_exec'))
180 curl_setopt($ch, CURLOPT_URL,
"http://www.dwalker.co.uk/versions/phpMySQLAutoBackup.php");
181 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
182 $newest_version=curl_exec($ch);
197 if ($version!=$newest_version)
return "*WARNING: upgrade required! Please visit: http://www.dwalker.co.uk/phpmysqlautobackup/ ";
207 $options = array(PDO::ATTR_PERSISTENT =>
true,PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
210 return $this->dbconn;
212 catch (PDOException $e){ $this->
reportDBError($e->getMessage()); }
217 if (
DEBUG) print_r(
'<div style="padding:10%;"><h3>'.nl2br($msg).
'</h3></div>');
220 if(!session_id()) session_start();
221 $_SESSION[
'pmab_mysql_errors'] =
"\n\nMySQL error: ".$msg.
"\n";
228 if (!isset(self::$instance)) self::$instance =
new self();
233 try {
return $this->dbconn->prepare(
$query); }
234 catch (PDOException $e){ $this->
reportDBError($e->getMessage()); }
238 try {
return $this->dbconn->bindParam(
$query); }
239 catch (PDOException $e){ $this->
reportDBError($e->getMessage()); }
244 if ($this->
query(
$query))
return $this->fetchAll();
247 catch (PDOException $e){ $this->
reportDBError($e->getMessage().
"<hr>".$e->getTraceAsString()); } }
251 catch (PDOException $e){ $this->
reportDBError($e->getMessage().
"<hr>".$e->getTraceAsString()); }
255 if (
$result->execute())
return $result->fetchAll(PDO::FETCH_ASSOC);
258 catch (PDOException $e){ $this->
reportDBError($e->getMessage().
"<hr>".$e->getTraceAsString()); }
266 $this->dbconn = null;