2013-10-22 108 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