thinkphp3.2 Uploadify upload GUID is only called once in an upload how to implement?

Source: Internet
Author: User
What I want to achieve is that the uploadify upload image into the database automatically generate tokens to think of the GUID

The upload class is using the thinkphp itself upload class results inserted into the database found that each picture is different
such as this



This is how uploadyify is processed after uploading.
  Public Function uploadify () {if (!empty ($_files)) {$config =array (' maxSize ' = 1024 000,//attachment size ' savepath ' = ' attachment/picture/uploadify/',//Attachment save path ' Savename ' =>array (' u Niqid ', '),//Accessory save name ' exts ' =>array (' jpg ', ' jpeg ', ' png ', ' gif ', ' rar ', ' zip '),//Attachment type ' autosub ' =            >true,//Open subdirectory save ' subname ' =>array (' Date ', ' YMD ')//subdirectory naming rules);            $upload =new \think\upload ($config);            $files _upload= $upload->upload (); if ($files _upload) {foreach ($files _upload as $file) {//$info = $files _upload[' filedate ' [' Sav                 Epath ']. $files _upload[' Filedata ' [' savename '];//file name after uploading $savename = $file [' Savename '];// File name before uploading $name = $file [' name '];//upload file type $type = $file [' EX T '];//upload file size k $size = $file [' Size '];//upload Directory $path = $file [' Savepath ']. $file [' SubName ']. $file [' Savename '];                    $attachment =d (' picture_attachment ');                    $date [' Creattime ']=date (' y-m-d h:i:s ', Time ());                    $date [' Pictureurl ']= $path;                    $date [' oldname ']= $name;                    $date [' newname ']= $savename;                    $date [' picturesize ']= $size;                    $date [' PictureType ']= $type;                        $date [' pictureid '] = $this->guid ();//Token GUID if ($attachment->create ($date)) {                        $attachment->add ();                   Session (' GUID ', $date [' Pictureid ']);                   /* Return to the foreground JS call */echo $path;                        } else{Unlink ($path. $type);                    Session ("Filesinfo", null);            }                } ;       }else{/* Return error message */         $info = $this->error ($upload->geterror (), U (' Picture/add '), 30);            Echo $info;        }} else{echo ' Upload file is empty '; }//End}


This is the time to traverse the uploaded file to generate a call $date [' pictureid '] = $this->guid () How this is done only once
So the GUID of a multi-figure token is the same ~ Ask the big God to guide specific how to do ah trouble familiar with the TP3.2 of God help ~ Thank you


Reply to discussion (solution)

Does that mean this? $date [' pictureid '] = $this->guid ();//Token GUID
You do it in the loop, it's not the same every time.
You put it in front of the loop, don't you just do it once?

Does that mean this? $date [' pictureid '] = $this->guid ();//Token GUID
You do it in the loop, it's not the same every time.
You put it in front of the loop, don't you just do it once?



This is not a problem is not the use of the upload class itself?

This class exceeds the limit of 1W characters .....
The great God who is familiar with TP if you see the problem with the way it's handled here, it doesn't work outside the loop.
thinkphp\library\think\upload.class.php


Does that mean this? $date [' pictureid '] = $this->guid ();//Token GUID
You do it in the loop, it's not the same every time.
You put it in front of the loop, don't you just do it once?



This is not a problem is not the use of the upload class itself?

This class exceeds the limit of 1W characters .....
The great God who is familiar with TP if you see the problem with the way it's handled here, it doesn't work outside the loop.
thinkphp\library\think\upload.class.php


Put a
$upload =new \think\upload ($config);
$files _upload= $upload->upload ();
The two methods implemented in the Upload class
   Array (),//Allow upload of file MIME type ' maxSize ' = + 0,//upload file size limit (0-No limit) ' exts ' = = Array (),// Allow upload of file suffix ' autosub ' = true,//Auto subdirectory save file ' subname ' = = Array (' Date ', ' y-m-d '),//subdirectory creation mode, [0]-function name, [1]-parameter, multiple parameters use array ' rootpath ' = ', '/' Save root path ' savepath ' = ', '//save path ' Saven Ame ' = = Array (' uniqid ', '),//upload file naming rules, [0]-function name, [1]-parameter, multiple parameters using array ' saveext ' = ' + ',//File save suffix, empty then use original post Prefix ' Replace ' = true,//existence of the same name overwrite ' hash ' = true,//whether to generate hash code ' callback ' = > False,//detects if a file exists callback, if there is a return file information array ' driver ' + ',//File Upload drive ' driverconfig ' = = Array (),    Upload drive configuration); /** * Upload Error message * @var String */private $error = ';    Upload error message/** * Upload Driver instance * @var Object */private $uploader; /** * Construction method for constructing upload instance * @param array $config configuration * @param string $driver The upload driver local-local upload driver to use, ftp-ftp upload driver */Public function __construct ($config = Array (), $driver = ' ', $driverConfig = null) {/* get configuration        */$this->config = Array_merge ($this->config, $config);        /* Set Upload driver */$this->setdriver ($driver, $driverConfig);                /* Adjust the configuration to convert the string configuration parameter to an array */if (!empty ($this->config[' mimes ')) {if (is_string ($this->mimes)) {            $this->config[' mimes '] = explode (', ', $this->mimes);        } $this->config[' mimes ' = Array_map (' Strtolower ', $this->mimes); } if (!empty ($this->config[' exts ')) {if (is_string ($this->exts)) {$this->config[            ' exts '] = explode (', ', $this->exts);        } $this->config[' exts ' = Array_map (' Strtolower ', $this->exts); }}/** * upload file * @param file information array $files, usually $_files array */Public function upload ($files = ") {if ('       ' = = = $files) {$files = $_files; } if (empty ($files)) {$this->error = ' no uploaded file!            ';        return false; }/* detects the upload root directory */if (! $this->uploader->checkrootpath ($this->rootpath)) {$this->error =            $this->uploader->geterror ();        return false; }/* Check the Upload directory */if (! $this->uploader->checksavepath ($this->savepath)) {$this->error = $            This->uploader->geterror ();        return false;        }/* Detect and upload files individually */$info = array ();        if (function_exists (' Finfo_open ')) {$finfo = Finfo_open (Fileinfo_mime_type);            }//To the uploaded file array information processing $files = $this->dealfiles ($files);            foreach ($files as $key = + $file) {if (!isset ($file [' key ')]) $file [' key '] = $key;  /* Get file types by extension to resolve problems with the Flash upload $files array return file type Error */if (Isset ($finfo)) {$file [' type '] = Finfo_file         ($finfo, $file [' tmp_name ']);   }/* Get upload file suffix, allow upload no suffix file */$file [' ext '] = pathinfo ($file [' name '], pathinfo_extension);            /* File Upload detection */if (! $this->check ($file)) {continue;                }/* Gets the file hash */if ($this->hash) {$file [' md5 '] = md5_file ($file [' tmp_name ']);            $file [' sha1 '] = sha1_file ($file [' tmp_name ']);            }/* Call the callback function to detect if the file exists */$data = Call_user_func ($this->callback, $file); if ($this->callback && $data) {if (File_exists ('. ').                    $data [' path ']) {$info [$key] = $data;                Continue            }elseif ($this->removetrash) {call_user_func ($this->removetrash, $data);//delete trash according to}            }/* Generate save File name */$savename = $this->getsavename ($file);            if (false = = $savename) {continue;           } else {     $file [' savename '] = $savename;            }/* Detects and creates subdirectories */$subpath = $this->getsubpath ($file [' name ']);            if (false = = = $subpath) {continue;            } else {$file [' savepath '] = $this->savepath. $subpath;            }/* Strict detection of image files */$ext = Strtolower ($file [' ext ']); if (In_array ($ext, Array (' gif ', ' jpg ', ' jpeg ', ' BMP ', ' png ', ' SWF '))) {$imginfo = getimagesize ($file [' Tmp_name ']                ); if (Empty ($imginfo) | | ($ext = = ' gif ' && empty ($imginfo [' bits '])) {$this->error = ' Illegal image file!                    ';                Continue                }/* Save the file and record the file that was successfully saved */if ($this->uploader->save ($file, $this->replace)) {                unset ($file [' Error '], $file [' tmp_name ']);            $info [$key] = $file;            } else {$this->error = $this->uploader->geterror ();    }    } if (Isset ($finfo)) {finfo_close ($finfo); } return empty ($info)?    False: $info; }/** * Convert the uploaded file array variable to the correct way * @access private * @param array $files uploaded file variable * @return Array */PRIV        Ate function Dealfiles ($files) {$fileArray = array ();        $n = 0; foreach ($files as $key = + $file) {if (Is_array ($file [' name '])) {$keys = Array_keys ($fi                Le);                $count = count ($file [' name ']);                    for ($i =0; $i < $count; $i + +) {$fileArray [$n] [' key '] = $key;                    foreach ($keys as $_key) {$fileArray [$n][$_key] = $file [$_key][$i];                } $n + +;               }}else{$fileArray = $files;            Break    }} return $fileArray; }

is not the problem here?
/* Detect and upload files individually */
$info = Array ();
if (function_exists (' Finfo_open ')) {
$finfo = Finfo_open (Fileinfo_mime_type);
}
Information processing for an array of uploaded files
$files = $this->dealfiles ($files);
foreach ($files as $key = = $file) {
if (!isset ($file [' key ')]) $file [' key '] = $key;
/* Get file type by extension to solve the problem of returning file type errors in the Flash upload $files array */
if (Isset ($finfo)) {
$file [' type '] = Finfo_file ($finfo, $file [' tmp_name ']);
}
  • 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.