php - Rename file name using uploadify -


this question has answer here:

i uploading image using uploadify,the problem is,in model changing file name pass uploadify funciton.now want file name renamed in model in onuploadcomplete property of uploadify.im alerting file name display same file name uploading. here code:-

        'buttontext'      : 'select',         'filetypedesc'    : 'image files',         'filetypeexts'    : '*.gif; *.jpg; *.png',         'swf'             :'<?php echo base_url()?>resources/flash/uploadify.swf',         'uploader'        :'<?php echo base_url().'user/upload_temp';?>',         'width'           : 40,         'multi'           :false,         'onuploadcomplete':function(file)         {             alert(file.name);             $('.select_div').hide();             $('.original').hide();             $('#image1').attr('style','background-image:url("./resources/images/users/temp/'+file.name+'");background-size: 76px 76px;');             $('.default').hide();             $('#image2').attr('style','background-image:url("./resources/images/users/temp/'+file.name+'");background-size: 73px 66px;position:absolute; height:66px; width:73px; top:256px; left:220px;');             $('#hidden_img_value1').attr('value',file.name)         }     }); 

and in model im doing :- $targetfolder = fcpath.'/resources/images/users/temp/'; // relative root if (!empty($image)) { $time=strtotime("now"); $image['filedata']['name']=$time.'.jpg'; $tempfile = $image['filedata']['tmp_name']; $targetpath = $targetfolder.$image['filedata']['name'];

        // validate file type         $filetypes = array('jpg','jpeg','gif','png'); // file extensions         $fileparts = pathinfo($image['filedata']['name']);          if (in_array($fileparts['extension'],$filetypes))          {             move_uploaded_file($tempfile,$targetpath);             echo '1';         }          else          {             echo 'invalid file type.';         }     } 

   // validate file type     $filetypes = array('jpg','jpeg','gif','png'); // file extensions     $fileparts = pathinfo($image['filedata']['name']);      if (in_array($fileparts['extension'],$filetypes))      {         move_uploaded_file($tempfile,$targetpath);         // set new name       $new_name = rand(0,10000).'.'.$fileparts['extension'];       $new_path = $fileparts['dirname'].'/'.$new_name;        while(file_exists($new_path))      {       $new_name = rand(0,10000).'.'.$fileparts['extension'];       $new_path = $fileparts['dirname'].'/'.$new_name;      }        rename($targetpath,$new_path);      }      else      {         echo 'invalid file type.';     } } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -