- by admin
There is an error while sending mail in Mac OS X Mountain Lion 10.8:send-mail: fatal: chdir /Library/Server/Mail/Data/spool: No such file or directory
sudo mkdir -p /Library/Server/Mail/Data/spool
sudo /usr/sbin/postfix set-permissions
sudo /usr/sbin/postfix start
- by admin
Another (and more easy) way to change text in multiple files is to use grep:grep -lr -e 'oldtext' * | xargs sed -i 's/oldtext/newtext/g'
perl -p -i -e ’s/oldtext/newtext/g’ *
- by admin
Just after I posted this article the second more easy solution has been found. Here it is:# sed -i 's/[orginal_text]/[new_text]/' filename.txt
# cat database.txt
LOCAL_DATABASE = 192.168.1.16
LOCAL_DIR = /home/calvin/
PROD_DB = 192.168.1.16
# sed -i 's/192.168.1.16/192.168.1.22/g' database.txt
# cat database.txt
LOCAL_DATABASE = 192.168.1.22
LOCAL_DIR = /home/calvin/
PROD_DB = 192.168.1.22
# cat database.txt
LOCAL_DATABASE = 192.168.1.16
LOCAL_DIR = /home/calvin/
PROD_DB = 192.168.1.16, 192.168.1.16
# sed -i 's/192.168.1.16/192.168.1.22/' database.txt
# cat database.txt
LOCAL_DATABASE = 192.168.1.22
LOCAL_DIR = /home/calvin/
PROD_DB = 192.168.1.22, 192.168.1.16
# find . -maxdepth 1 -name "*.txt" -type f -exec sed -i 's/wine/champagne/' {} \
- by admin
Error:postdrop: warning: uid=48: File too large
% /usr/sbin/postconf -e message_size_limit=XXXXXXXXXXX
% postconf -e mailbox_size_limit=0
# postconf -d | grep size
berkeley_db_create_buffer_size = 16777216
berkeley_db_read_buffer_size = 131072
body_checks_size_limit = 51200
bounce_size_limit = 50000
header_size_limit = 102400
mailbox_size_limit = 51200000
message_size_limit = 10240000
- by admin
Here what I found and like most.// Set the allowed types for reading and upload.
$types = array ('jpg', 'jpeg', 'txt');
// Start a variable.
$dir_files = array();
// If it is a directory add all the files.
if (is_dir ($dir)) {
// Open the directory.
if ($handle = opendir($dir)) {
// Read the file names of all the files available.
while (false !== ($file = readdir($handle))) {
// Make sure the file is not this directory or its parent and not the .DS_Store file.
if ($file != "." && $file != ".." && $file != '.DS_Store') {
// Get the file parts.
$file_parts = pathinfo($file);
// Make sure the extension is allowed.
if (in_array(strtolower ($file_parts['extension']),$types)) {
// Add the file to the array.
$dir_files[] = array ('original_name'=>$file, 'type'=>$file_parts['extension']);
}
}
}
// Close the handle.
closedir ($handle);
}
}
// If any files exist in the upload directory check them for viruses.
if (count ($dir_files) > 0) {
// Get the dir and prepare it for the command line.
$real_path = realpath ($dir);
$safe_path = escapeshellarg($real_path);
// Set the variables for the cmd.
$return = -1;
$out ='';
$cmd = '/usr/local/clamXav/bin/clamscan ' . $safe_path;
// Execute the cmd.
exec ($cmd, $out, $return);
// If a virus is found loop through each of the files and delete the virus, write the user a message, and add them to a db table.
if ($return != 0) {
// Loop through the files.
foreach ($dir_files as $k=>$v) {
// Get the dir and prepare it for the command line.
$real_path = realpath ($dir . $v['original_name']);
$safe_path = escapeshellarg($real_path);
// Reset the values.
$return = -1;
$out ='';
$cmd = '/usr/local/clamXav/bin/clamscan ' . $safe_path;
// Execute the command.
exec ($cmd, $out, $return);
// If the file is clean do nothing.
if ($return == 0){}
// If the file contains a virus remove it and add a note to the db.
else if ($return == 1) {
// Delete the file.
unlink ($dir . $v['original_name']);
// Unset the file from the records.
unset ($dir_files[$k]);
// Notify the user.
$message .= "The file {$v['original_name']} contained a known virus. It has been deleted from the server.<br />";
$message_class = 'error';
// Add the user who uploaded the file to the db and a time and date.
// Query the db to record who uploaded the file, not necessary but fun info to have.
}
else {
// Delete the file.
unlink ($dir . $v['original_name']);
// Unset the file from the records.
unset ($dir_files[$k]);
// Notify the user.
$message .= "The file {$v['original_name']} caused an unknown error and was removed from the server.<br />";
$message_class = 'minor_error';
}
}
}
}
- by admin
Just some examples:$filename = 'sample.gif';
// 1. The "explode/end" approach
$ext = end(explode('.', $filename));
// 2. The "strrchr" approach
$ext = substr(strrchr($filename, '.'), 1);
// 3. The "strrpos" approach
$ext = substr($filename, strrpos($filename, '.') + 1);
// 4. The "preg_replace" approach
$ext = preg_replace('/^.*\.([^.]+)$/D', '$1', $filename);
// 5. The "never use this" approach
// From: http://php.about.com/od/finishedphp1/qt/file_ext_PHP.htm
$exts = split("[/\\.]", $filename);
$n = count($exts)-1;
$ext = $exts[$n];
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');
echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n"; // since PHP 5.2.0
/www/htdocs/inc
lib.inc.php
php
lib.inc