PHP MVC Framework SKYMVC support multiple file upload _php tips

Source: Internet
Author: User
Tags file upload learn php php code

This example for you to share the SKYMVC implementation of file upload specific code, for your reference, the specific content as follows

1. Code upload.ctrl.php

<?php
class Uploadcontrol extends skymvc{public
  
 function __construct () {
  parent::__construct ();
 }
  
 Public Function Ondefault () {
   
  $this->smarty->display ("upload/default.html");
 }
  
 Public Function Onupload () {
   
  $this->loadclass ("Upload");
  Uploaded file directory
  $this->upload->uploaddir= "attach/my/";
  File size allowed to upload
  $this->upload->maxsize=4194304000;
  Whether to upload pictures
  $this->upload->upimg=true;
  Set the file types that are allowed to be uploaded
  $this->upload->sysallowtype=array (' gif ', ' jpg ', ' bmp ', ' png ', ' jpeg ', ' txt ', ' mpeg ', ' avi ', ') ' RM ', ' rmvb ', ' wmv ', ' flv ', ' mp3 ', ' wav ', ' wma ', ' SWF ', ' Doc ', ' pdf ', ' zip ', ' tar ', ' svg ';
  $this->upload->allowtype= $this->upload->sysallowtype;
  Store
  $this->upload->iddir=0;
  by ID $data = $this->upload->uploadfile ("upimg");
  Print_r ($data);
  echo Json_encode ($data); 
   
 }
 
? >

2. Code upload.html

<!doctype html>  

3.PHP Code

 function skyupload (upid,url,success,error,uploadprogress) {var VFD = new FormData ();
   var f= document.getElementById (upid). files;
   $ ("#" +upid+ "Loading"). Show ();
   for (Var i=0;i<f.length;i++) {vfd.append (' upimg ', document.getElementById (upid). Files[i]);  
   var oxhr = new XMLHttpRequest ();
   Oxhr.addeventlistener (' Load ', success, false);
   Oxhr.addeventlistener (' Error ', error, false);
   if (uploadprogress!=undefined) {OXHR.upload.addEventListener ("Progress", uploadprogress, false);
   } oxhr.open (' POST ', url);
  
   Oxhr.send (VFD);
  }/* Function Uploadfinish (e) {var data=eval ("+e.target.responsetext+"));
  $ ("#uploading"). Hide () if (Data.error!= ') {skytoast (data.msg);
   }else {$ ("#imgShow"). HTML (" ');
   $ ("#imgurl"). Val (Data.imgurl); } function Uploaderror (e) {//Upload error Skytoast ("Out of Error");} */

The above is the entire content of this article, I hope that you learn PHP program help.

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.