-5

在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'];
4

2 回答 2

2

只需更换:

move_uploaded_file($_FILES["image"]["tmp_name"],"photos_user/" . $_FILES["image"]["name"]);

和:

move_uploaded_file($_FILES["image"]["tmp_name"],"photos_user/" . $fname);
于 2012-11-27T08:38:03.743 回答
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
?>
于 2012-11-27T08:38:44.290 回答