2016-08-11 4 views
0

プラグインを使用するには、ファイルをアップロードする必要があります。マニフェストファイルにファイルフィールドを追加する

マニフェストフィールドでは、enctype = "multipart/form-data"という形式が設定されていないため、ファイルをアップロードすると失われます。

これを変更する方法はありますか?

答えて

0
      form xml :  
          <field name="con_image" type="file" label="" description="" hint="Image"/> 
      default.php 
          <div class="controls"> 
              <?php if (!empty($this->item->con_image) && file_exists(JPATH_SITE.'/images/contact_image/thumb_' . $this->item->con_image)) : ?> 
               <img src="<?php echo JRoute::_(JUri::root() . 'images/contact_image/thumb_' . $this->item->con_image, false);?>"> 
              <?php endif; ?> 
               <input type="hidden" name="jform[con_image]" id="jform_image_hidden" value="<?php echo $this->item->con_image; ?>" /> 
               <?php echo $this->form->renderField('con_image'); ?> 
             </div> 
      your view table file code for image upload: 

      $files = $app->input->files->get('jform', array(), 'raw'); 

        $array = $app->input->get('jform', array(), 'ARRAY'); 

        if (!empty($files['con_image']['name'])) 
        { 
         // Deleting existing files 
         $oldFiles = PlansHelpersPlans::getFiles($this->id, $this->_tbl, 'con_image'); 

         foreach ($oldFiles as $f) 
         { 
          $oldFile = JPATH_ROOT . '/images/contact_image/' . $f; 


          if (file_exists($oldFile)) 
          { 
           unlink($oldFile); 
          } 

         } 

         $this->con_image = ""; 
         $singleFile = $files['con_image']; 

          jimport('joomla.filesystem.file'); 

          // Check if the server found any error. 
          $fileError = $singleFile['error']; 
          $message = ''; 

          if ($fileError > 0 && $fileError != 4) 
          { 
           switch ($fileError) 
           { 
            case 1: 
             $message = JText::_('File size exceeds allowed by the server'); 
             break; 
            case 2: 
             $message = JText::_('File size exceeds allowed by the html form'); 
             break; 
            case 3: 
             $message = JText::_('Partial upload error'); 
             break; 
           } 

           if ($message != '') 
           { 
            $app->enqueueMessage($message, 'warning'); 

            return false; 
           } 
          } 
          elseif ($fileError == 4) 
          { 
           if (isset($array['con_image'])) 
           { 
            $this->con_image = $array['con_image']; 
           } 
          } 
          else 
          { 

           // Replace any special characters in the filename 
           jimport('joomla.filesystem.file'); 
           $filename = JFile::stripExt($singleFile['name']); 
           $extension = JFile::getExt($singleFile['name']); 
           $filename = preg_replace("/[^A-Za-z0-9]/i", "-", $filename); 
           $filename = rand()."-".$filename . '.' . $extension; 
           $uploadPath = JPATH_ROOT . '/images/contact_image/' . $filename; 

           $fileTemp = $singleFile['tmp_name']; 

           if (!JFile::exists($uploadPath)) 
           { 
            if (!JFile::upload($fileTemp, $uploadPath)) 
            { 
             $app->enqueueMessage('Error moving file', 'warning'); 

             return false; 
            } 
           } 

           //$this->con_image .= (!empty($this->con_image)) ? "," : ""; 
           $this->con_image = $filename; 
          } 

        }else{ 
         $this->con_image = $array['con_image']; 
        } 

はまだあなたは問題が、その後、私の単純なコンポーネントのダウンロードはこちら を確認してください。私はその期待しhttps://github.com/erakashpatel/Important-notes/blob/master/com_helloworld.zip OR https://github.com/erakashpatel/Important-notes/blob/master/com_test.zip

を仕事があります。事前に感謝します。

0
for xml : 
      Joomla File form field type in xml: 
      https://docs.joomla.org/File_form_field_type 
      <field name="myfilevalue" type="file" label="Enter some text" description="Choose an image from your computer with maximum 100KB" size="10" accept="image/*" /> 


      OR 
      if your file field in html form then used : 
      <input type="file" name="jform[myfilevalue]" > 

私はその助けを願って、他の は、より多くの説明を提供してください

+0

こんにちは、お返事ありがとうございます。これは私がすでに持っているものです。私がしたいのは、そのファイルをアップロードできることです。これを行うには、 '

'タグの属性を 'enctype =" multipart/form-data "' – simon

+0

@simonに変更する必要があります。ここで説明するようにJavascriptを使ってenctypeを設定することができます - http:// www .w3schools.com/jsref/tryit.asp?filename = tryjsref_form_enctype2 – Irfan

関連する問題