php
  • file-upload
  • 2016-02-07 20 views 1 likes 
    1

    HTMLPHP文件上傳不工作 - 無法移動

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"> 
    <input type='file' name='uphoto' id='uphoto' accept='image/x-png, image/gif, image/jpeg, image/jpg' > 
    <input type="submit" name="submit" value="Submit Changes"> 
    

    PHP(profile.php)

    $target_dir = '/images/demo/profiles/'; 
        $target_file = $target_dir . basename($_FILES['uphoto']['name']); 
        $uploadOk = 1; 
        $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 
    
    
        if (!empty($_FILES['uphoto']['name'])) { 
         //echo 'A file was selected for upload'; 
    
         // check file size 
         if ($_FILES['uphoto']['size'] > 5000000) { 
          echo '<p style="color:red">Sorry, the photo must be smaller than 5MB.</p>'; 
          $uploadOk = 0; 
         } 
    
         // Allow certain file formats 
         if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") { 
          echo '<p style="color:red">Sorry, only JPG, JPEG, PNG & GIF files are allowed.</p>'; 
          $uploadOk = 0; 
         } 
    
         if ($uploadOk == 0) { 
          echo '<p style="color:red">Sorry, your file was not uploaded.</p>'; 
          // if everything is ok, try to upload file 
         } else { 
          if (move_uploaded_file($_FILES['uphoto']['tmp_name'], $target_file)) { 
           echo '<p style="color:green">The file '. basename($_FILES['uphoto']['name']). ' has been uploaded.</p>'; 
          } else { 
           echo '<p style="color:red">Sorry, there was an error uploading your file:'.var_dump($_FILES['uphoto']['error']).'</p>'; 
          } 
         } 
        } 
    

    ERROR VAR DUMP

    int(0) 
    

    錯誤日誌

    PHP警告:move_uploaded_file(/ images/demo/profiles/Blue hills.jpg): 無法打開流: /thermobi/bosoraweb103/b1029/ipg.domain/sd/profile.php無在線文件或目錄182 PHP Warning:move_uploaded_file():無法將'/ tmp/phpLeRQSS'移動到 '/ images/demo/profiles/Blue hills.jpg'中 /hermes/bosoraweb103/b1029/ipg.domain/sd/profile。 ph

    該表格實際上更復雜,除了文件上傳外,其他所有工作都是有效的。我只是修剪它,使其易於閱讀。我就這個問題聯繫了wed主機(iPage),但他們說他們的服務器工作正常,文件限制很大。

    +1

    可能相對路徑問題。檢查'$ target_file'路徑相對於* profile.php * –

    回答

    0
    $target_dir = './images/demo/profiles/'; 
    

    ,而不是

    $target_dir = '/images/demo/profiles/'; 
    
    相關問題