我正在尝试使用 php 同时上传两张图片。当我运行下面的代码时,没有任何内容显示为错误,并且图像未上传到我将它们移动到的文件夹中。第一个是缩略图,第二个是实际图像。
我添加error_reporting(E_ALL); ini_set('display_errors', '1');
了,屏幕上没有显示错误。
<?php
error_reporting(E_ALL); ini_set('display_errors', '1');
if(isset($_POST['submit'])){
if (isset($_FILES['newsthumb']) && isset($_FILES['newsmain'])) {
$allowedExts = array("jpg", "jpeg", "gif", "png");
$thumbimage = $_FILES['newsthumb'];
$mainimage = $_FILES['newsmain'];
$thumbname = strtolower($thumbimage['name']);
$mainmane = strtolower($mainimage['name']);
$thumbname = preg_replace("/[^A-Z0-9._-]/i", "_", $thumbname);
$mainmane = preg_replace("/[^A-Z0-9._-]/i", "_", $mainmane);
$thumbname = $thumbname.uniqid();
$mainmane = $thumbname.uniqid();
if (($thumbimage['size'] > 350000) || ($mainmane['size'] > 350000)) {
$error[] = "One/Both of the files are too large.<br>";
}
$uploaddir = "images/newsimage/";
$thumbsuccess = move_uploaded_file($thumbimage["tmp_name"], $uploaddir.$thumbname);
$mainsuccess = move_uploaded_file($mainimage["tmp_name"], $uploaddir.$mainmane );
}
}
?>
这是我正在使用的 HTML 表单:
<form enctype="multipart/form-data" action="<?php echo htmlentities($_SERVER['SCRIPT_NAME']) ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="9000000">
<h3>Thumbnail News Image: </h3>
<input name='newsthumb' type="file" class='Input_file' />
<h3>Full Image:></h3>
<input name='newsmain' type="file" class='Input_file' />
<input type="submit" name="commit" value="send">
</form>