0

您好我有一个脚本,允许用户上传图像,但它不上传图像。一切都很好,比如兰特号等,但图像不仅被上传。以下是我的图片上传表格。

    <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";
}
?>

在这个我的上传文件夹是用户,我也想知道上传后的文件名是什么,因为我想向用户展示它,所以我该怎么做。提前致谢!如果您需要更多信息,请询问我。

4

2 回答 2

1

HTML 表单照常执行,

下面的编码将根据生成自动创建一个新的文件夹编号,在该文件夹内它将包含上传。如果要更改上传的路径,请使用/的\INSTEAD,因为它会导致错误。

注册.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/>"; 
}

}   

}
?>
于 2012-10-03T09:31:51.430 回答
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";
}
?>
于 2012-10-03T07:47:42.303 回答