PHP-如何插入上传到MySQL的新文件名
我正在上传多图像文件并成功重命名。 但是,我不知道如何获取我用函数move\u uploaded\u file()重命名的文件名。我想获取要插入mySQL的新名称PHP-如何插入上传到MySQL的新文件名,php,html,mysql,Php,Html,Mysql,我正在上传多图像文件并成功重命名。 但是,我不知道如何获取我用函数move\u uploaded\u file()重命名的文件名。我想获取要插入mySQL的新名称 if(isset($_POST['submit'])) { $count=count($_FILES["images"]["name"]); for($i=0;$i<$count;$i++) { if ((($_FILES["images"]["type"][
if(isset($_POST['submit']))
{
$count=count($_FILES["images"]["name"]);
for($i=0;$i<$count;$i++)
{
if ((($_FILES["images"]["type"][$i] == "image/gif")
|| ($_FILES["images"]["type"][$i] == "image/jpeg")
|| ($_FILES["images"]["type"][$i] == "image/png"))
&& ($_FILES["images"]["size"][$i] < 100000))
{
if ($_FILES["images"]["error"][$i] > 0)
{
echo "File Error : " . $_FILES["images"]["error"][$i] . "<br />";
}
else
{
// echo "Upload File Name: " . $_FILES["images"]["name"][$i] . "<br />";
// echo "File Type: " . $_FILES["images"]["type"][$i] . "<br />";
//echo "File Size: " . ($_FILES["images"]["size"][$i] / 1024) . " Kb<br />";
if (file_exists("images/location/".$_FILES["images"]["name"][$i] ))
{
echo "<b>".$_FILES["images"]["name"][$i] . " already exists. </b>";
}
else
{
move_uploaded_file($_FILES["images"]["tmp_name"][$i] ,"images/location/"."NEW_NAME!!!".$i.".jpg" );
// echo "Stored in: " . "images/location/" . $_FILES["images"]["name"][$i] ."<br />";
?>
<?php
}
}
}else
{
echo "Invalid file detail ::<br> file type ::".$_FILES["images"]["type"][$i] ." , file size::: ".$_FILES["images"]["size"][$i] ;
}
}
}
if(isset($\u POST['submit']))
{
$count=count($_文件[“图像”][“名称]);
对于($i=0;$i 0)
{
回显“文件错误:”.$\u文件[“图像”][“错误”][$i]。“
”;
}
其他的
{
//echo“上传文件名:”.$\u文件[“图像”][“名称”][$i]。“
”;
//echo“文件类型:”.$\u文件[“图像”][“类型”][$i]。“
”;
//回显“文件大小:”。($_文件[“图像”][“大小”][$i]/1024)。“Kb
”;
如果(文件存在(“图像/位置/”$\u文件[“图像”][“名称”][$i]))
{
echo“$\u文件[“图像”][“名称”][$i]”已存在;
}
其他的
{
移动上传的文件($\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\;
//echo“存储在:“.images/location/”$_文件[“images”][“name”][$i]。“
”;
?>
我在我的项目中使用了这个
$temp = explode(".", $_FILES['image']['name']);
$name = round(microtime(true)) . substr(md5(rand()), 0, 4) . '.' . end($temp);
move_uploaded_file($_FILES['image']['tmp_name'], $name);
//this is for single image upload
//Here $name is the new image name. You can then use your mysql_insert function to insert new image name to the database
//to upload multiple file just pass the file name as an array,tmp_name as an array
public function __attachments_upload($name, $tmp_name) {
foreach ($name as $key => $value) {
$temp = explode(".", $value);
$name = round(microtime(true)) . substr(md5(rand()), 0, 4) . '.' . end($temp);
move_uploaded_file($tmp_name[$key], $name);
//here you can use mysql_insert
}
}
'test_file.'.'$\u FILES[“images”][“name”][$i]这是旧名称。我可以插入一次吗?mysql中有3列(pic1、pic2、pic3)你有固定图像吗,比如3?如果有,那么使用答案的前3行创建一个函数,并为每个图像调用它。或者你可以将你的图像数组传递到_附件_上传函数如果你认为答案是可以的,你能接受答案吗
$temp = explode(".", $_FILES['image']['name']);
$name = round(microtime(true)) . substr(md5(rand()), 0, 4) . '.' . end($temp);
move_uploaded_file($_FILES['image']['tmp_name'], $name);
//this is for single image upload
//Here $name is the new image name. You can then use your mysql_insert function to insert new image name to the database
//to upload multiple file just pass the file name as an array,tmp_name as an array
public function __attachments_upload($name, $tmp_name) {
foreach ($name as $key => $value) {
$temp = explode(".", $value);
$name = round(microtime(true)) . substr(md5(rand()), 0, 4) . '.' . end($temp);
move_uploaded_file($tmp_name[$key], $name);
//here you can use mysql_insert
}
}