上传的图片路径正在增加一倍

时间:2015-09-26 04:31:23

标签: php codeigniter grocery-crud

http://localhost/name/Projects/work/CodeIgniter223Grocery151Smarty3127_Pack/uploads/http://site名称//上传/ Card_Designs_vqd1q1o8.jpg

         public function uploadEdesignimage()
           {
              $data=$this->data; // for geting paths


                $id=$this->session->userdata('id');
                $email=$this->session->userdata('email');
                 $data['getuser']=$this->ecard_model->getUser($id);
                 $name=$data['getuser']->name;

                $createdon= date('Y-m-d H:i:s');
                $temptype= $_POST['temptype'];
                $path = $_FILES['uplaodimg']['name'];


                $imgext=strtolower(strrchr($path,'.'));
                 $imgname="Card_Designs_".$this-     >generateRandomString().$imgext;
                if($path!='')
                 {

                    $im= $this->config->item('base_url').'/uploads'.'/'.$imgname;

                    $x=$this->do_upload($imgname);
                     $img=array('image'=>$im,'name'=>$name,'email'=>$email,'designtype'=>$temptype,'createdon'=>$createdon);
                    $this->ecard_model->insertUploadedImages($img);



                    }

                     }    this is my controller function

// ajax用于上传图片

           $("#uploadimage").on('submit',(function(e) {

          if ($('#uplaodimg').val()!='' & $('#temptype').val()!='')
           {
              e.preventDefault();
               var f=$('#uplaodimg')[0].files[0].size/1024;

                  if (f > 1024)
                    {
                        $("#msgsizeupload").removeAttr('style');
                     }
                    else
                     {
                       $("#sucessimage").empty();
                       $("#Msgupdbtn").attr('disabled','disabled');
                       $('#divMsgupd').show();

                        $.ajax({
                         url: "{{$site}}/ecarddesigns/uploadEdesignimage", // Url to which the request is send

                           type: "POST",             // Type of request to be send, called as method           
                            data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
                             contentType: false,       // The content type used when sending data to the server.
                              cache: false,             // To unable request pages to be cached   
                                 processData:false,        // To send DOMDocument or non processed data file it is set to false
                                 success: function(data)   // A function to be called if request succeeds
                                    {
                                       //alert(data);  die();
                                        $('#divMsgupd').hide();
                                                                             $("#msgafterupload").removeAttr('style');
                                      setTimeout(function()
                                          {
                                         window.location="{{$site}}/ecarddesigns/loadEdesign";
                                         }, 5000);
                                              }
                                          });
                                        }    
                                        }
                                       else
                                          { 
                                        e.preventDefault();
                                  if ($('#uplaodimg').val()=='')
                                    {
                                $('#imageupload_err').html('Please select the image before upload')
                                        }
                                            else
                                               {
                                        $('#imageupload_err').html('Please select the design type')
                                           }
                                         }

                                         }));

用于获取image.modal,使用ajax。

0 个答案:

没有答案