Php 上载图像未按预期工作
我有一个表单,用户填写多个输入字段,他们还可以上传图像。我最近添加了另一个输入字段,用户可以在其中上载其他图像Php 上载图像未按预期工作,php,Php,我有一个表单,用户填写多个输入字段,他们还可以上传图像。我最近添加了另一个输入字段,用户可以在其中上载其他图像 <label for="photo">Facility Roof Plan:</label> <input type="file" id="facilityroofplan" name="facilityroofplan" /> 这就是我的save\u facility\u roof\u plan功能的外观
<label for="photo">Facility Roof Plan:</label>
<input type="file" id="facilityroofplan" name="facilityroofplan" />
这就是我的save\u facility\u roof\u plan
功能的外观:
function save_facility_roof_plan($from, $to, $status_msg) {
// Check if file already exists
if (file_exists($to)) {
$status_msg = "Sorry, facility photo already exists.";
return false;
}
if (move_uploaded_file($from, $to)) {
$status_msg = "The file ".basename($to)." has been uploaded.";
return true;
}
$status_msg = "Sorry, there was an error uploading a photo.";
return false;
}
我已经在其他几个地方这样做了,我上传任何图片都没有问题
我哪里出了问题 在代码中,有一行
$saved = save_facility_roof_plan($from, $facilityPhoto, $status_msg);
但是在你发布的内容中没有变量$facilityPhoto
。我猜应该改为$FacilityRofPlan
,因为您设置了该路径,但从未使用过它
然后,永远不会检查$saved
变量是否存在错误,这些错误可能会向您说明它不起作用的原因
尝试:
这是什么&函数中的第三个参数解决了这个问题?你的移动上传对我来说太疯狂了……试试这个‘移动上传’文件($移动上传文件[“文件上传”][“tmp\u名称”],$target\u文件])`该死,忘了更改它了!另外,感谢您的额外检查,我想知道为什么没有显示任何内容。谢谢你的帮助!
$saved = save_facility_roof_plan($from, $facilityPhoto, $status_msg);
$facilityRoofPlan = "../images/". $selectedAssocAccount ."/" . $facilityID . "/" . basename($_FILES["facilityroofplan"]["name"]);
if($_FILES['facilityroofplan']['error'] == UPLOAD_ERR_OK) {
$status_msg = '';
$from = $_FILES["facilityroofplan"]["tmp_name"];
$saved = save_facility_roof_plan($from, $facilityRoofPlan, $status_msg);
if (!$saved) {
echo "Error saving roof plan image: {$status_msg}";
}
} else{
echo "Error uploading facility image.";
}