Use jquery uploadify in PHP to upload multiple images

Source: Internet
Author: User
Tags mkdir php file php and

jquery Uploadify is an AJAX-style batch image upload plug-in, in PHP using jquery uploadify is very convenient, please follow the methods and procedures described in this article, for your PHP program to increase the jquery uploadify plugin bulk upload image features.

This article is based on dilicms, to increase the image upload function.

1. Add Data table dili_fieldtypes new field:k=>image,v=> picture upload area (Vachar);

2. Modify the application/libraries/dili/field_behavior.php and add the following code to the switch:

1case ' image ':

2$field=array (

3 ' type ' => ' VARCHAR ',

4 ' constraint ' =>255,

5 ' Default ' => '

6);

7break;

3. Modify the application/libraries/dili/form.php and add the following code:

1function _image ($fileld, $default) {

2//$type = ' Type=hidden ';

3//$width = ($field [' width ']? $field [' Width ']: ' 570 '). ' px; ';

4//$height = ($field [' height ']? $field [' Height ']: ' 415 '). ' px; ';

5return;

6}

4. Increase the judgment code in content_form.php and category_content_form.php:

01

if ($v [' type ']== "image"):

03?>

04

05

06

07 Upload

08 Cancel Upload

09

"Value=" "/>

One "value=" "/>"

12asset/js/uploadify/uploadify.css "type=" Text/css "rel=" stylesheet "/>"

13

14

42

6. New photo.php File:

01

02IF (! defined (' BasePath ')) exit (' No Direct script access allowed ');

03date_default_timezone_set (' Asia/shanghai ');

04class Photo extends front_controller{

The Public Function __construct ()

06 {

Modified parent::__construct ();

08}

function _getfilepath ()

10 {

One $path = "attachments/". Date ("Y"). " /";

if (!file_exists ($path)) {

mkdir ($path, ' 777 ');

14}

$path. =date ("M"). " /";

if (!file_exists ($path)) {

mkdir ($path, ' 777 ');

18}

return $path;

20}

function _creat_photothumbs ($FileName, $setW) {

$IMGInfo = getimagesize ($FileName);

if (! $IMGInfo) return false;

if ($IMGInfo [' MIME ']== ' image/pjpeg] | | $IMGInfo [' MIME ']== ' Image/jpeg ') {

$ThisPhoto = Imagecreatefromjpeg ($FileName);

}elseif ($IMGInfo [' MIME ']== "image/x-png" | | | $IMGInfo [' MIME ']== ' Image/png ') {

$ThisPhoto = Imagecreatefrompng ($FileName);

}elseif ($IMGInfo [' MIME ']== "Image/gif") {

$ThisPhoto =imagecreatefromgif ($FileName);

30}

$width = $IMGInfo [' 0 '];

$height = $IMGInfo [' 1 '];

$scale = $height/$width;

$NW = $setW;

$NH = $NW * $scale;

$NewPhoto =imagecreatetruecolor ($NW, $NH);

Panax Notoginseng imagecopyresampled ($NewPhoto, $ThisPhoto, 0,0,0,0, $NW, $nh, $width, $height);

Imagejpeg ($NewPhoto, $FileName);

return true;

40}

The _savephoto_post function () {

$dest _dir = $this->_getfilepath ();

if (!empty ($_files)) {

$date = Date (' Ymd ');

A//$dest _dir = $this->_getfilepath ();

$photoname = $_files["Filedata"] [' name '];

$phototype = $_files[' filedata '] [' type '];

$photosize = $_files[' filedata '] [' size '];

$fileInfo =pathinfo ($photoname);

$extension = $fileInfo [' extension '];

$newphotoname = Date ("Ymdhis"). Mt_rand (10000,99999). $extension;

$dest = $dest _dir $newphotoname;

//move_uploaded_file ($_files[' filedata '] [' tmp_name '], Iconv ("UTF-8", "gb2312", $dest));

Move_uploaded_file ($_files[' filedata '] [' tmp_name '], $dest);

//chmod ($dest, 0755);

56///If width is greater than 600 to crop

$arr =getimagesize ($dest);

if ($arr [0]>600) {

$thumb _w=600;

$this->_creat_photothumbs ($dest, $thumb _w);

61}

62//Generate thumbnails

$config 2[' image_library '] = ' gd2 ';

$config 2[' source_image '] = $dest;

$config 2[' create_thumb '] = TRUE;

$config 2[' maintain_ratio '] = TRUE;

$config 2[' width '] = 170;

$config 2[' height '] = 150;

$config 2[' Master_dim ']= "width";

$config 2[' thumb_marker ']= "_1";

$this->load->library (' Image_lib ', $config 2);

$this->image_lib->resize ();

Echo $dest;

74}

75}

76}

77?>

Well, it's ready to be tested.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.