我无法管理图库中的图像。例如,如果abc.jpg已经存在。如果我尝试上传具有相同名称(abc.jpg)的图像,则先前的图像将被替换为新图像。所以我想用一个随机数作为图像名称重命名图像(即当前日期+时间+随机数)。这是我的代码
<?php
session_start();
include("includes/connect.php");
$name= $_SESSION['email'];
if (!isset($_FILES['image']['tmp_name'])) {
echo "";
}else{
$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/" . $_FILES["image"]["name"]);
$location="photos/" . $_FILES["image"]["name"];
$pname=$_POST['p_name'];
$email= $_SESSION['email'];
$category=$_POST['category'];
$dimention=$_POST['dimention'];
$desc=$_POST['description'];
$price=$_POST['price'];
$status=$_POST['status'];
$dop=$_POST['dou'];
$save=mysql_query("insert into paintings (location,p_name,email,category,dimention,description,price,status,dou,varify) values ('$location','$pname','$email','$category','$dimention','$desc','$price','$status','$dop','0')")or die(mysql_error());
$result= mysql_query ("select p_id from paintings ORDER BY p_id DESC LIMIT 1");
$row=mysql_fetch_array($result);
$pid=$row['p_id'];
$save1=mysql_query("insert into upload (email,p_id,u_date) values ('$name','$pid',now())")or die(mysql_error());
header('Location: user_profile.php');
}
答案 0 :(得分:1)
$newfile=date('d-m-Y')."_".rand(0000,9999).$_FILES['image']['name'];
$image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name= addslashes($_FILES['image']['name']);
move_uploaded_file($_FILES["image"]["tmp_name"],"photos/" . $newfile);
答案 1 :(得分:0)
$filename=$_FILES["image"]["name"];
$final_name=time().$filename;
这将有效我想我们不需要随机数,因为我们使用unix时间戳。为了简单起见
Dim x as variant
x = (Workbooks(stripfile).Sheets(1).Cells(C, Defect_data_col + i).Text
Workbooks(strip_concat).Sheets(1).Cells(A, 5) = Right(Left(x,r),1