2010-07-22 224 views
0

獲取未定義索引:文件名錯誤,下面的圖片上傳php代碼。下面的代碼中是否有任何問題?PHP圖片上傳問題

<div id="content"> 
    <form class="wufoo" action=<?php echo (BASE_PATH. 'admin/addbusinessdetail'); ?> method="post"> 
      <input type="hidden" name="maxSize" value="9999999999" /> 
      <input type="hidden" name="maxW" value="200" /> 
      <input type="hidden" name="fullPath" value="<?php echo (BASE_PATH. 'public/img/uploads/'); ?>" /> 
      <input type="hidden" name="relPath" value="<?php echo (BASE_PATH. 'public/img/uploads/'); ?>" /> 
      <input type="hidden" name="colorR" value="255" /> 
      <input type="hidden" name="colorG" value="255" /> 
      <input type="hidden" name="colorB" value="255" /> 
      <input type="hidden" name="maxH" value="300" />   
     <ul> 
      <li> 
     <label class="desc">Business Type</label> 
      <br /> 
        <div> 
         <select class="field select" name="ddltype" style="width:300px; height: 30px;"> 
          <?php 
           $types = $this->_data; 
           foreach ($types as $value) { 
            foreach($value as $innvalue){ 
             $businessname[] = $innvalue; 
             } 
             echo('<option value="'.$businessname[0].'">'.$businessname[1].'</option>'); 
             unset($businessname); 
           } 
          ?> 
         </select> 
        </div> 
     </li> 
     <li> 
     <label class="desc">Business Detail <span class="req">*</span></label> 
        <br /> 
      <div> 
         <input type="text" class="field text" name="businessname" style="width: 300px; height: 20px;" /> 
      </div> 
     </li> 
      <li> 
     <label class="desc">Business Website <span class="req">*</span></label> 
        <br /> 
      <div> 
         <input type="text" class="field text" name="website" style="width: 300px; height: 20px;" /> 
      </div> 
     </li> 
      <li> 
     <label class="desc">Business Email <span class="req">*</span></label> 
        <br /> 
      <div> 
         <input type="text" class="field text" name="email" style="width: 300px; height: 20px;" /> 
      </div> 
     </li> 
      <li> 
     <label class="desc">Business Image <span class="req">*</span></label> 
        <br /> 
      <div> 
         <input type="file" name="filename" /> 
      </div> 
     </li> 
      <li> 
     <label class="desc">Address <span class="req">*</span></label> 
        <br /> 
      <div> 
         <textarea name="address" cols="50" rows="8" ></textarea> 
      </div> 
     </li> 
     <li class="buttons"> 
      <input class="submit" type="submit" value="Save" /> <input class="submit" type="button" value="Cancel" onClick="history.back()" /> 
     </li> 
     </ul> 

    </form> 

addbusinessdetail控制器

function addbusinessdetail() 
      { 
       print_r($_FILES['filename']); 
       $this->Admin->addbusinessdetail(); 
       $this->businessdetails(0,0); 
      } 
+0

獲取未定義的索引:文件名錯誤我下面的圖片上傳php代碼。下面的代碼中是否有任何問題? – 2010-07-22 03:04:12

+0

是你的形式'multipart/form-data'?...請過

標籤,它的內容... 另外,我會在調用數組之前總是做一個'if(isset())'評估。 [編輯]哎呀,當添加此評論正確的代碼是不是在問題.. – 2010-07-22 03:06:30

回答

2

添加到您的表單標籤:

enctype="multipart/form-data" 

如果你正在做一個文件上傳,你讓Web服務器知道需要這種形式的屬性預計文件data.Here的文件上傳更多信息:http://www.tizag.com/phpT/fileupload.php

+0

偉大的,它工作正常。謝謝! – 2010-07-22 03:05:42