【发布时间】:2012-10-03 07:36:22
【问题描述】:
您好,我有一个脚本允许用户上传图像,但它不上传图像。一切都很好,比如兰特号等,但图像不仅被上传。以下是我的图片上传表单。
<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";
}
?>
在此我的上传文件夹是用户,我也想知道上传后的文件名是什么,因为我想向用户展示它,所以我该怎么做。提前致谢! 如果您需要更多信息,请咨询我。
【问题讨论】:
-
html 表单看起来不错,但 PHP 脚本看起来很混乱。例如,'$user_image'变量在哪里定义?常量'none'是什么意思?
-
$http_post_files 已弃用,请改用 $FILES['user_image']['name']
-
您是否收到任何错误返回?您的上传位置是否设置了适当的权限(chmod 755 或 777)?
-
只需尝试按照以下链接中提到的步骤w3schools.com/php/php_file_upload.asp
-
@darshan.dodiya 嘿,我从那里得到了脚本,但我也想重命名它的名字,你能告诉我怎么做吗?
标签: php html image file-upload