Tag Archives: php

php test upload file owner

<?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);
                }
        }
?>

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";
}
}

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

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.

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