<?php if(isset($_FILES['image'])){ $errors= array(); $file_name = $_FILES['image']['name']; $file_size =$_FILES['image']['size']; $file_tmp =$_FILES['image']['tmp_name']; $file_type=$_FILES['image']['type']; $file_ext=strtolower(end(explode('.',$_FILES['image']['name']))); $expensions= array("jpeg","jpg","png"); if(in_array($file_ext,$expensions)=== false){ $errors[]="extension not allowed, please choose a JPEG or PNG file."; } if($file_size > 2097152){ $errors[]='File size must be excately 2 MB'; } if(empty($errors)==true){ move_uploaded_file($file_tmp,"tmp/".$file_name); echo "Success"; }else{ print_r($errors); } } ?>
Tag Archives: php
php check port
$host = 'stackoverflow.com';
$ports = array(21, 25, 80, 81, 110, 443, 3306);
foreach ($ports as $port)
{
$connection = @fsockopen($host, $port);
if (is_resource($connection))
{
echo '
' . $host . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open.
' . "\n";
fclose($connection);
}
else
{
echo '
' . $host . ':' . $port . ' is not responding.
' . "\n";
}
}
date(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function.
[Date]
date.timezone = "Europe/Vilnius"
php append to file
$txt = "user id date";
$myfile = file_put_contents('logs.txt', $txt.PHP_EOL , FILE_APPEND);
ubuntu apache create new virtual host
cp -v /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/test.com.conf
a2ensite test.com.conf
ubuntu install suphp
a2dismod php5
apt-get install libapache2-mod-suphp
a2enmod suphp
install laravel framework
cd /var/www/html
php /path/to/composer.phar create-project laravel/laravel --prefer-dist
Download failed: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
Download failed: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
file_get_contents(): Failed to enable crypto
file_get_contents(https://getcomposer.org/composer.phar): failed to open stream: operation failed
Downloading…
Fix:
apt-get install curl
php -r "readfile('http://getcomposer.org/installer');" | php
cloudlinux install composer globaly for all users
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
vi /etc/cagefs/conf.d/composer.cfg
[composer]
comment=Composer
paths=/usr/local/bin/composer
cagefsctl --force-update
phpci
PHPCI is a free and open source continuous integration tool specifically designed for PHP. Built with simplicity in mind and featuring integrations with all of your favourite testing tools, we’ve created the very best platform for testing your PHP projects.
centos 6 install php54
yum install centos-release-SCL
yum install php54 php54-*
/opt/rh/php54/root/usr/bin/php
php warnings: comments starting with ‘#’ are deprecated
If you get such messages when you are restarting httpd or when you looking form php information, fast fix:
php –ini
this will show you all you php ini filesm then:
find /php/ini/patch -iname test.ini -exec sed -i -re ‘s/^(\s*)#(.*)/\1;\2/g’ {} \;
php find and replace string
find . -iname ‘*php’ | xargs grep ‘search-string’ -sl | while read x; do echo $x; sed -i ‘s/search-string/replace-string/’ $x; done
php shell_exec
$output = shell_exec(‘ls -lart’);
echo “
$output
“;
startup script for memcached processes
#!/bin/sh
#
# memcached Startup script for memcached processes
#
# chkconfig: – 90 10
# description: Memcache provides fast memory based storage.
# processname: memcached
# These mappings correspond one-to-one with Drupal’s settings.php file.
[ -f memcached ] || exit 0
prog=”memcached”
start() {
echo -n $”Starting $prog ”
# Sessions cache.
memcached -m 16 -l 0.0.0.0 -p 11211 -d -u nobody
# Default cache.
memcached -m 32 -l 0.0.0.0 -p 11212 -d -u nobody
# Block cache.
memcached -m 32 -l 0.0.0.0 -p 11213 -d -u nobody
# Content cache. Holds fully loaded content type structures.
memcached -m 16 -l 0.0.0.0 -p 11214 -d -u nobody
# Filter cache. Usually the busiest cache after the default.
memcached -m 32 -l 0.0.0.0 -p 11215 -d -u nobody
# Form cache.
memcached -m 32 -l 0.0.0.0 -p 11216 -d -u nobody
# Menu cache.
memcached -m 32 -l 0.0.0.0 -p 11217 -d -u nobody
# Page cache. Bigger than most other caches.
memcached -m 128 -l 0.0.0.0 -p 11218 -d -u nobody
# Views definition cache.
memcached -m 1 -l 0.0.0.0 -p 11219 -d -u nobody
# Views data cache (may need to be increased if heavily used).
memcached -m 32 -l 0.0.0.0 -p 11220 -d -u nobody
# More caches that might be added later:
# Users table.
#/usr/bin/memcached -m 24 -l 0.0.0.0 -p 11219 -d -u nobody
# Path source cache.
#/usr/bin/memcached -m 4 -l 0.0.0.0 -p 11220 -d -u nobody
# Path destination cache.
#/usr/bin/memcached -m 6 -l 0.0.0.0 -p 11221 -d -u nobody
RETVAL=$?
echo
return $RETVAL
}
stop() {
if test “x`pidof memcached`” != x; then
echo -n $”Stopping $prog ”
killall memcached
echo
fi
RETVAL=$?
return $RETVAL
}
case “$1” in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
condrestart)
if test “x`pidof memcached`” != x; then
stop
start
fi
;;
*)
echo $”Usage: $0 {start|stop|restart|condrestart}”
exit 1
esac
exit $RETVAL