我看到的大多数问题都与一个图像输入有关。但是,如果您有 2 个或 3 个或更多呢?
我的一个图像输入脚本有效,但我试图在我的表单中输入一个单图像输入和一个多图像输入。我正在测试我的表单上有 2 个单图像输入但不工作。
这是一个单一图像输入的 HTML(假设它位于 <form> 标记内):
<input type="hidden" name="size" value="350000"/>
<input type="file" name="schoollogo"/><br/>
PHP:
$target = "images/logo/";
$target = $target . basename( $_FILES['schoollogo']['name']);
$schoollogo = $_FILES['schoollogo']['name'];
//Writes the information to the database
mysql_query("INSERT INTO Colleges (schoollogo) VALUES ('$schoollogo')") or die(mysql_error()) ;
//Writes the logo to the server
if (move_uploaded_file($_FILES['schoollogo']['tmp_name'], $target)) {
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
} else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
对于第二个单图像输入,我只是添加了第二个输入代码......
<input type="hidden" name="size" value="350000"/>
<input type="file" name="otherimage"/><br/>
然后将变量添加到 PHP 中:
$targetotherimage = "images/otherimage/";
$targetotherimage = $targetotherimage . basename( $_FILES['otherimage']['name']);
mysql_query("INSERT INTO Colleges (schoollogo,otherimage) VALUES ('$schoollogo','$otherimage')") or die(mysql_error()) ;
//Writes the logo to the server
if (move_uploaded_file($_FILES['schoollogo']['tmp_name'], $target)) && (move_uploaded_file($_FILES['otherimage']['tmp_name'], $targetotherimage)) {
但是当将该代码添加到 PHP 中时,该代码不起作用。没有错误消息或任何东西。页面是空白的。
顺便说一句,这是我的另一个问题,我正在尝试使用已经工作的单图像上传输入将多图像上传输入添加到我的表单中。