Php 移动\u上传的\u文件不工作,没有扩展名
我正在尝试用php脚本将图像上传到web服务器。图像通过HTML表单上传。 上载到服务器的图像没有文件扩展名,因此保存为文本文件。但是,在服务器上打开它们时,我可以看到图像 这里是我的php脚本的摘录。Php 移动\u上传的\u文件不工作,没有扩展名,php,Php,我正在尝试用php脚本将图像上传到web服务器。图像通过HTML表单上传。 上载到服务器的图像没有文件扩展名,因此保存为文本文件。但是,在服务器上打开它们时,我可以看到图像 这里是我的php脚本的摘录。 $image1 = $_FILES['image1']['tmp_name']; $filepath1 = "./images/"; $filepath1 = $filepath1 . basename($image1); move_uploaded_file($image1, $filepa
$image1 = $_FILES['image1']['tmp_name'];
$filepath1 = "./images/";
$filepath1 = $filepath1 . basename($image1);
move_uploaded_file($image1, $filepath1);
这是服务器文件管理器的一个片段。
$image1 = $_FILES['image1']['tmp_name'];
$filepath1 = "./images/";
$filepath1 = $filepath1 . basename($image1);
move_uploaded_file($image1, $filepath1);
您必须使用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']);
您在保存图像时使用的是临时文件名而不是上载的文件名,这就是为什么上载的图像没有扩展名。使用
$\u文件['image1']['name']
作为目标文件,而不是$\u文件['image1']['tmp\u name']
。