gpt4 book ai didi

php - 多文件上传

转载 作者:行者123 更新时间:2023-11-29 12:38:11 24 4
gpt4 key购买 nike

寻找以下解决方案:

表单 html/php 提供添加多个图形文件的功能(最多 11 个文件,最大 5MB)。

发送到服务器脚本时应执行以下操作:

  • 检查文件的扩展名是否正确(jpg、png);
  • 根据公式<最多32个字符的字符串>_<000到010>重新命名每个文件。 <扩展名>;
  • 将文件名添加到表格中(一个文件=一列、一行);
  • 压缩至最大分辨率 1280x1024;
  • 更改 4:3 图像上的图形比例,同时保持相同比例;
  • 减小文件大小并保存到服务器的适当文件夹中。

我对可能易于使用的解决方案感兴趣。
非常感谢您的帮助。

最佳答案

尝试一下,

HTML 代码

<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Multiple File Ppload with PHP</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" id="file" name="files[]" multiple="multiple" accept="image/*" />
<input type="submit" value="Upload!" />
</form>
</body>
</html>

PHP 代码

<?php
$valid_formats = array("jpg", "png");
$max_file_size = 1280*1024;
$path = "uploads/"; // Upload directory
$count = 0;

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
// Loop $_FILES to exeicute all files
foreach ($_FILES['files']['name'] as $f => $name) {
if ($_FILES['files']['error'][$f] == 4) {
continue; // Skip file if any error found
}
if ($_FILES['files']['error'][$f] == 0) {
if ($_FILES['files']['size'][$f] > $max_file_size) {
$message[] = "$name is too large!.";
continue; // Skip large files
}
elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
$message[] = "$name is not a valid format";
continue; // Skip invalid file formats
}
else{ // No error found! Move uploaded files
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
$count++; // Number of successfully uploaded file
}
}
}
}
?>

关于php - 多文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26463534/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com