Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 图像上载结果名称问题_Php_Image_Upload - Fatal编程技术网

Php 图像上载结果名称问题

Php 图像上载结果名称问题,php,image,upload,Php,Image,Upload,您好,我有一个上载脚本,可以将图像上载到图像文件夹,但是上载的图像如下所示: 5353ee0e7ef05_13 及 5353ee0e7f08c_13座椅平面图 名字应该是13和13seatplan,有办法解决这个问题吗?代码如下: foreach ($_FILES['file']['name'] as $f => $name) { $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $na

您好,我有一个上载脚本,可以将图像上载到图像文件夹,但是上载的图像如下所示:

5353ee0e7ef05_13

5353ee0e7f08c_13座椅平面图

名字应该是13和13seatplan,有办法解决这个问题吗?代码如下:

foreach ($_FILES['file']['name'] as $f => $name) {
 $allowedExts = array("gif", "jpeg", "jpg", "png");
    $temp = explode(".", $name);
    $extension = end($temp);

if ((($_FILES["file"]["type"][$f] == "image/gif")
|| ($_FILES["file"]["type"][$f] == "image/jpeg")
|| ($_FILES["file"]["type"][$f] == "image/jpg")
|| ($_FILES["file"]["type"][$f] == "image/png"))
&& ($_FILES["file"]["size"][$f] < 2000000)
&& in_array($extension, $allowedExts))
{
  if ($_FILES["file"]["error"][$f] > 0)
  {
    echo "Return Code: " . $_FILES["file"]["error"][$f] . "<br>";
  }
  else
  {

    if (file_exists("images/" . $name))
    {

    }
    else
    {
        move_uploaded_file($_FILES["file"]["tmp_name"][$f], "images/" . uniqid() . "_" . $name);
    }
  }
}
else
{
    $error =  "Invalid file";
}
}
foreach($\u FILES['file']['name']作为$f=>$name){
$allowedExts=数组(“gif”、“jpeg”、“jpg”、“png”);
$temp=分解(“.”,$name);
$extension=end($temp);
如果(($_FILES[“file”][“type”][$f]==“image/gif”)
||($_FILES[“file”][“type”][$f]==“image/jpeg”)
||($_FILES[“file”][“type”][$f]==“image/jpg”)
||($_FILES[“file”][“type”][$f]==“image/png”))
&&($_文件[“文件”][“大小”][$f]<2000000)
&&in_数组($extension$allowedExts))
{
如果($_FILES[“file”][“error”][$f]>0)
{
回显“返回代码:”..$\u文件[“文件”][“错误”][$f]。“
”; } 其他的 { 如果(文件_存在(“图像/”$name)) { } 其他的 { 移动上传的文件($\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\$f],“图像/”.uniqid().“\\\\$name); } } } 其他的 { $error=“无效文件”; } }

我认为上传时命名有问题,但我不知道问题出在哪里,谢谢

啊,我知道了,这是uniqid()的问题。

还有一个可能会帮助您在
|
if子句中留出一些
。我会研究一下,谢谢