我的代码出了问题,其中已上传的图片只有表格中的一张,其中我选择了5张图片。
这是我的file-upload-employer.php
//Screen.java
package game.graphics;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.ArrayList;
import javax.swing.JPanel;
import entities.BodyParts;
public class Screen extends JPanel implements Runnable{
public static final int WIDTH = 800, HEIGHT = 800;
private Thread thread;
private boolean running = false;
private BodyParts b;
private ArrayList<BodyParts> snake;
private int ticks;
private int X = 10, Y = 10, size = 5;
private boolean right = false, left = true, up=false, down = false;
public Screen()
{
setPreferredSize(new Dimension(WIDTH, HEIGHT));
snake = new ArrayList<BodyParts>();
Start();
}
public void Start()
{
running = true;
thread = new Thread(this, "game loop");
thread.start();
}
public void tick()
{
if(snake.size() == 0)
{
b = new BodyParts(X, Y, 10);
snake.add(b);
}
ticks++;
if(ticks > 2500)
{
//check the direction of movement
if(right) {X++;}
if(left) {X--;}
if(up) {Y++;}
if(down) {Y--;}
ticks = 0;
b = new BodyParts(X, Y, 10);
snake.add(b);
if(snake.size() > size)
{
snake.remove(0);
}
}
}
public void paint(Graphics g)
{
//g.clearRect(0, 0, WIDTH, HEIGHT);
g.setColor(Color.BLACK);
for(int i = 0;i<WIDTH/10 ;i++)
{
g.drawLine(i*10, 0, i*10, HEIGHT);
}
for(int i = 0;i<HEIGHT/10 ;i++)
{
g.drawLine( 0, i*10, WIDTH, i*10);
}
for(int i = 0; i < snake.size() ;i++)
{
snake.get(i).draw(g);
}
}
public void Stop()
{
}
@Override
public void run() {
// TODO Auto-generated method stub
while(running)
{
tick();
repaint();
}
}
}
// BodyParts.java
package entities;
import java.awt.Color;
import java.awt.Graphics;
public class BodyParts {
private int X, Y, width, height;
public BodyParts(int X, int Y, int tile)
{
this.X = X;
this.Y = Y;
width = tile;
height = tile;
}
public void tick()
{
}
public void draw(Graphics g)
{
g.setColor(Color.black);
g.fillRect(X*width, Y*height, width, height);
g.setColor(Color.GREEN);
g.fillRect(X*width + 2, Y*height + 2, width-4, height-4);
}
}
这里是我放下相册名称并选择图片的表格。
<?php
include('admin/db/database_configuration.php');
$sql = "SELECT * FROM tblalbums ORDER BY album_id DESC LIMIT 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
$row = $result->fetch_assoc();
$wow = $row['album_id'];
echo ($row['album_id']);
} else {
echo "0 results";
}
$conn->close();
?>
<?php
include('admin/db/database_configuration.php');
if (isset($_FILES["userfile"]) && !empty($_FILES["userfile"])) {
$image = $_FILES['userfile']['tmp_name'];
$imageSize = $_FILES['userfile']['size'];
$imageType = $_FILES['userfile']['type'];
$imageName = $_FILES['userfile']['name'];
if (empty($_POST['aname'])){$albumname = 'NULL'; } else{ $albumname ="'". mysqli_real_escape_string($conn, $_POST['aname']) . "'";}
$len = count($image);
$path = "admin/images/";
for ($i = 0; $i < $len; $i++) {
if (isset($imageName[$i]) && $imageName[$i] !== NULL) {
if(move_uploaded_file($image[$i], $path.$imageName[$i])) {
$sql = "INSERT INTO `tblalum_photos` (imageName, imageSize, imageType, album_id) VALUES ('$imageName[$i]','$imageSize[$i]', '$imageType[$i]',$wow+1);";
$sql .= "INSERT INTO `tblalbums` (albumName) VALUES ($albumname)";
if ($conn->multi_query($sql) === TRUE) {
echo '<script>alert("Images Sent")</script>';
echo '<script>window.location = "contact_us.php"</script>';
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
}
}
}
$conn->close();
?>
如果我不包含其他sql <form method="post" enctype="multipart/form-data" autocomplete="off">
<input type="text" class="desc" name="aname" placeholder="Album Name" style="width: 250px;" />
<?php include'admin/upload-preview.php' ?>
<br><br>
Select photo to send
<div class="col-sm-12" id="result"> </div>
<input id="files" type="file" name="userfile[]" multiple/><br>
<button class="btn btn-danger" type="button" id="clear">CLEAR</button>
<button id="yes" type="submit" name="save" formaction="file-upload-employer.php" class="btn btn-success">UPLOAD</button>
</form>
,则会正确上传,但我必须将相册名称与照片一起提供。
感谢您将来的答案。