move_uploaded_file不工作,没有扩展名

问题描述 投票:-2回答:1

我试图在我的PHP脚本中将图像上传到Web服务器。图像通过HTML表单上传。上传到服务器的图像没有文件扩展名,因此保存为文本文件。但是,在服务器上打开它们,我可以看到图像。

这是我的PHP脚本的摘录。

$image1 = $_FILES['image1']['tmp_name'];
$filepath1 = "./images/";
$filepath1 = $filepath1 . basename($image1);

move_uploaded_file($image1, $filepath1);

这是服务器文件管理器的片段。

enter image description here

php
1个回答
0
投票

您必须使用image1的name属性。

你可以尝试这样做:

$tmp_path = $_FILES['image1']['tmp_name'];
$file_path = "./images/";

$new_path = $file_path . $_FILES['image1']['name'];

move_uploaded_file($tmp_path, $new_path);

var_dump($_FILES['image1']);
© www.soinside.com 2019 - 2024. All rights reserved.