【发布时间】:2014-05-10 21:40:00
【问题描述】:
好的,在我的网站中,用户可以上传图片作为他们的个人资料照片,我将它们保存为 $username.jpg,因此所有图片文件名都是唯一的。问题是它们都保存在我的根目录中,使那里的一切变得一团糟。那么我需要什么样的脚本来自动将所有照片保存在一个名为“profileimages”的文件夹中?
这几乎是我目前拥有的代码。
Select an image: <br/> <input type="file" name="profilepicture" size="10" />;
if ($_FILES) {
if($_FILES['profilepicture']['name']){
$name = $_FILES['profilepicture']['name'];
switch($_FILES['profilepicture']['type']){
case 'image/jpeg': $ext = 'jpg'; break;
default: $ext = ''; break;
}
if ($ext == ''){
echo '<script> alert("Your uploaded file is of the wrong file type, only jpeg image file types are accepted"); </script>';
}
if ($ext){
$profimg = "$user.$ext";
move_uploaded_file($_FILES['profilepicture']['tmp_name'], $profimg);
}
}
}
【问题讨论】: