2013-10-22 107 views
0

我試圖讓下面的php文件上傳腳本工作,我已經在所有變量上使用了var_dump()和print_r,並且據我所知它應該工作。事實上,這是工作...在我的Windows安裝,我目前正在運行的Ubuntu 12.04,由於某種原因,這不會在我的本地設置工作,我不願意嘗試它的生活,這可能是我的/ tmp /權限?PHP文件上傳返回錯誤

<?php 
    function upload() { 
     /*  * * check if a file was uploaded ** */ 
     if (is_uploaded_file($_FILES['images']['tmp_name']) && getimagesize($_FILES['images']['tmp_name']) != false) { 
      /*   * * get the image info. ** */ 
      $size = getimagesize($_FILES['images']['tmp_name']); 
      /*   * * assign our variables ** */ 
      $type = $size['mime']; 
      $imgfp = fopen($_FILES['images']['tmp_name'], 'rb'); 
      $size = $size[3]; 
      $name = $_FILES['images']['name']; 
      $maxsize = 99999999; 
      $target_path = "/uploads/"; 
      /* Add the original filename to our target path. 
       Result is "uploads/filename.extension" */ 
      $currentDate = date("Y-m-d"); 
      $target_path = $target_path . $currentDate . ' - ' . basename($_FILES['images']['name']); 
      /*   * * check the file is less than the maximum file size ** */ 
      if ($_FILES['images']['size'] < $maxsize) { 
           if (move_uploaded_file($_FILES['images']['tmp_name'], $target_path)) { 
        echo "The file " . basename($_FILES['images']['name']) . 
        " has been uploaded"; 

       } else { 
        echo "<div class='error'>There was an error uploading the file, please <a href='../artworkGenerator'>try again!</a></div>"; 
       } 
      } else { 
       /*    * * throw an exception if image is not of type ** */ 
       throw new Exception("File Size Error"); 
      } 
     } else { 
      // if the file is not less than the maximum allowed, print an error 
      throw new Exception("Unsupported Image Format!"); 
     } 
     print_r(); 
    } 

    /* * * check if a file was submitted ** */ 
    if (!isset($_FILES['images'])) { 
     echo '<p>Please select a file</p>'; 
    } else { 
     try { 
      upload(); 
      /*   * * give praise and thanks to the php gods ** */ 
      echo '<p>Thank you for submitting</p>'; 
     } catch (Exception $e) { 
      echo '<h4>' . $e->getMessage() . '</h4>'; 
     } 
    } 
    ?> 

上傳形式:

<form id="uploadForm" enctype="multipart/form-data" action="upload.php" method="POST"> 


           <input type="hidden" name="MAX_FILE_SIZE" value="99999999" /> 
           <label>Attach file<span class="required"> *</span></label><img style="display:none;float:right;position: relative;top: 45px;right: 5px;" class="logo" src="img/tick.png" alt="logo" /> 
           <hr class="small"/> 
           <br/> 
           <input type="file" name="images" id="images" multiple /> 
           <ul id="image-list"> 
           </ul> 
           <br/><br/> 
          <hr style="clear:both"> 
         <input class="btn btn-success save" type="submit" id="btn" value="Generate"/> 

         <div id="invisible" style="display:none;"> 
         </div> 
        </form> 
+0

你能告訴你的文件上傳表單HTML文件夾? –

+0

可能有一些問題,如「upload_max_filesize」或任何其他設置的PHP配置 – PravinS

+0

我已經添加了文件上傳表單.. – dyatesupnorth

回答

0

你嘗試過製作上傳路徑相對於執行這個PHP文件多數民衆贊成?

此外,它可能是一個權限錯誤,從而做一個快速檢查搭配chmod 777你想保存到

+0

我chmodded我的文件夾,但仍然沒有運氣,雖然我懷疑它的一個Ubuntu的問題 – dyatesupnorth

+0

它不應該是我在大多數發行版中都使用ubuntu。如何使上傳路徑更相對?而不是$ target_path =「/ uploads /」;使其相對於PHP文件,如$ target_path =「../uploads」; – ninjr

+0

而不是'我應該使用什麼? – dyatesupnorth