gpt4 book ai didi

php上传文件名修改

转载 作者:可可西里 更新时间:2023-11-01 01:04:03 25 4
gpt4 key购买 nike

我需要有关使用 php 上传多个文件的帮助。当我上传具有不同字符名称的文件时,它会更改文件名,例如,如果它的 "Kayıt.doc"上传后变为 "Kayıt.doc" .我不想发生这种情况,我该怎么办?请帮助.... :)

这是html页面....

<!doctype html>
<html>
<body>
<form action="cvupload.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="539" height="75" border="0">
<tr>
<td width="220"><div align="right">Step 2 : </div></td>
<td width="309">Please upload your cv now </td>
</tr>
<tr>
<td><span class="style14">Submit your cv (ms word / zip format)</span></td>
<td><label for="file"></label>
<input type="file" name="file[]" id="file" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><label for="Submit"></label>
<input type="submit" name="Submit" value="Submit" id="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>

这是 PHP 页面...

<?php

$toplam = count($_FILES["file"]["name"]);
for ($i = 0; $i < $toplam; $i++)
{
foreach ($_FILES['file']['name'] as $filename)
{


if (((($_FILES["file"]["type"][$i] == "application/msword")||($_FILES["file"]["type"][$i] == "application/zip")))
&& ($_FILES["file"]["size"][$i] > 0))
{
if ($_FILES["file"]["error"][$i] > 0)
{

echo "Return Code: " . $_FILES["file"]["error"][$i] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"][$i] . "<br />";
echo "Type: " . $_FILES["file"]["type"][$i] . "<br />";
echo "Size: " . ($_FILES["file"]["size"][$i] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"][$i] . "<br />";

if (file_exists("upload/" . $_FILES["file"]["name"][$i]))
{
echo $_FILES["file"]["name"][$i] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"][$i],
"upload/" . $_FILES["file"]["name"][$i]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"][$i];
}
}
}
else
{
echo "Invalid file";

}
}
?>

当我像这样不使用括号时 <input type="file" name="file" id="file" />仅 1 个文件没问题,但多个文件不起作用。

最佳答案

谢谢大家的回复,我这样改了代码,成功了。

move_uploaded_file($_FILES["file"]["tmp_name"][$i], "upload/" . iconv("UTF-8", "ISO-8859-9//TRANSLIT",$_FILES["file"]["name"][$i]));

关于php上传文件名修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15569928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com