2012-10-03 110 views
0

嗨,我有一個腳本,它允許用戶上傳圖像,但它不上傳圖像。一切都很好,像蘭特編號等,但圖像不僅被上傳。以下是我的圖片上傳表單。PHP腳本不上傳圖像

<form action="register.php" method="post" enctype="multipart/form-data" name="regForm" id="regForm" > 
     <table width="95%" border="0" cellpadding="3" cellspacing="3" class="forms"> 
      <tr> 
       <td>Profile Image<span class="required"><font color="#CC0000">*</font></span> </td> 
       <td><input name="user_image" type="file" class="required password" id="user_image"> 
        <span class="example">Upload your image</span> 
        <input name="doRegister" type="submit" id="doRegister" value="Register"> 
       </td> 
      </tr> 
     </table> 
    </form> 

這是register.php

<?php 
$path = "user/".time().uniqid(rand()).basename($_FILES['user_image']['name'],'.'); 
if($user_image !=none) 
{ 
     move_uploaded_file($_files['user_image']['tmp_name'], $path); 
     { 
      echo "Successful<BR/>"; 
      echo "File Name :".$HTTP_POST_FILES['user_image']['name']."<BR/>"; 
      echo "File Size :".$HTTP_POST_FILES['user_image']['size']."<BR/>"; 
      echo "File Type :".$HTTP_POST_FILES['user_image']['type']."<BR/>"; 
      echo "<img src=\"$path\" width=\"150\" height=\"150\">"; 
     } 
} 
else 
{ 
    echo "Error"; 
} 
?> 

在此我上傳文件夾是用戶,我也想知道,什麼是被上傳後的文件名,因爲我想展示給用戶,所以我該怎麼做。提前致謝! 如果你需要更多的信息問我。

+0

HTML表單看起來不錯,但PHP腳本看起來混亂。例如,'$ user_image'變量在哪裏定義?常量'none'的含義是什麼? –

+0

$ http_post_files已棄用使用$ FILES ['user_image'] ['name']而不是 – Furry

+0

您是否收到任何返回的錯誤?您的上傳位置是否設置了適當的權限(chmod 755或777)? – Mike

回答

0
<?php 


if(isset($_FILES['user_image'])) 
{ 
$path = "user/".time().uniqid(rand()).basename($_FILES['user_image']['name'],'.'); 

    move_uploaded_file($_files['user_image']['tmp_name'], $path); 
    { 
     echo "Successful<BR/>"; 
     echo "File Name :".$HTTP_POST_FILES['user_image']['name']."<BR/>"; 
     echo "File Size :".$HTTP_POST_FILES['user_image']['size']."<BR/>"; 
     echo "File Type :".$HTTP_POST_FILES['user_image']['type']."<BR/>"; 
     echo "<img src=\"$path\" width=\"150\" height=\"150\">"; 
    } 
} 
else 
{ 
    echo "No File Chosen"; 
} 
?> 
1

HTML表單做像往常一樣,

下面的編碼將自動創建一個基於生成新文件夾號,該文件夾裏邊有它將由上傳。如果您想更改上傳的路徑,請使用/的\ \ INSTEAD,因爲它會導致錯誤。

Register.php

if ($_POST['doRegister'] == "Register") 
{ 

    $path1 = "C:\Uploads\ "; 
    if (file_exists($path1)) 
    { 
    $path = $path1 .time().uniqid(rand()).'\ '; 


$target_path = $path . basename($_FILES['user_image']['name']); 

if(move_uploaded_file($_FILES['user_image']['tmp_name'], $target_path)) { 
    echo "Successfully uploaded on $path".$_FILES['user_image']['name']."<br>"; 

    echo "File Name :".$_FILES['user_image']['name']."<BR/>"; 
      echo "File Size :".$_FILES['user_image']['size']."<BR/>"; 
      echo "File Type :".$_FILES['user_image']['type']."<BR/>"; 
} 
    } 
else 
{ 

    mkdir($path1); 
    $path = $path1 .time().uniqid(rand()).'\ '; 
mkdir($path); 

$target_path = $path . basename($_FILES['user_image']['name']); 

if(move_uploaded_file($_FILES['user_image']['tmp_name'], $target_path)) { 
    echo "Successfully uploaded on $path".$_FILES['user_image']['name']."<br>"; 

    echo "File Name :".$_FILES['user_image']['name']."<BR/>"; 
      echo "File Size :".$_FILES['user_image']['size']."<BR/>"; 
      echo "File Type :".$_FILES['user_image']['type']."<BR/>"; 
} 

} 

} 
?>