在mysql上传时将图像重命名为用户名
$file=$_FILES['image']['tmp_name'];
$image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name= addslashes($_FILES['image']['name']);
move_uploaded_file($_FILES["image"]["tmp_name"],"photos_user/" . $_FILES["image"]["name"]);
$location="photos_user/" . $_FILES["image"]["name"];
我的用户名是
$fname= $_POST['fname'];
答案 0 :(得分:2)
只需替换:
move_uploaded_file($_FILES["image"]["tmp_name"],"photos_user/" . $_FILES["image"]["name"]);
使用:
move_uploaded_file($_FILES["image"]["tmp_name"],"photos_user/" . $fname);
答案 1 :(得分:0)
试试这个:
<?php
$fname = $_POST['fname'];
$file=$_FILES['image']['tmp_name'];
$image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name= addslashes($_FILES['image']['name']);
//$location="photos_user/" . $_FILES["image"]["name"];
move_uploaded_file($_FILES["image"]["tmp_name"],"photos_user/" . $fname.".jpg"); // <--- altered here
?>