下面是我修改过的代码,并根据我的网站需求进行了修改。它抓取图像,然后单独上传,制作缩略图,然后将数据记录到数据库中。
我遇到的麻烦是,当我一次上传5/6时,它有时不上传任何内容,也没有说明错误。我添加了(error_reporting(~0); ini_set('display_errors',1);)来检查错误,但仍然没有发现任何事情发生了什么。
非常感谢任何帮助。
PS: - php.ini设置为: -
upload_max_filesize = 60M
post_max_size = 60M
max_execution_time = 90
max_file_uploads = 30
PHP
$j = 0;
$target_path = "../../images/";
$newimagenumber=$currentimages;
$imgname = 0;
$ImgFileName = 0;
for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
$target_path = "../../images/";
$imgname = 0;
$ImgFileName = 0;
$newimagenumber=$newimagenumber+1;
$imgname=$_POST['FileName'];
$validextensions = array("jpeg", "jpg", "png", "JPG");
$ext = explode('.', basename($_FILES['file']['name'][$i]));
$file_extension = end($ext);
$ImgFileName="$imgname-$newimagenumber";
$ImgFileNameExt="$imgname-$newimagenumber.jpg";
$target_path = $target_path . $ImgFileName . ".jpg";
$j = $j + 1;
if (($_FILES["file"]["size"][$i] < 5000000) && in_array($file_extension, $validextensions)) {
if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {
$InsertImgFile = mysql_query("INSERT INTO image_data (image_url,image_name,image_customerid,FileName) VALUES ('$ImgFileNameExt','$ImgFileNameExt','$customer_id','$imgname')") or die(mysql_error());
include('CreateNails.php');
// If file moved to uploads folder.
echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/>';
} else { // If File Was Not Moved.
echo $j. ').<span id="error">please try again!.</span><br/>';
}
} else { // If File Size And File Type Was Incorrect.
echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/>';
}
}
}
答案 0 :(得分:1)
如果问题是您无法从总共6个文件中上传第6个文件,则问题出在您的计数器上
for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
您的文件数量必须小于/等于计数器,否则您将错过最后一个文件,假设$_FILES['file']
为6且您的计数器也为6,但您放置条件<
以便它将忽略第6个文件,所以你的conidtion必须是<=
for ($i = 0; $i <= count($_FILES['file']['name']); $i++) {