我是PHP的新手,并尝试上传多张图片,因为现在它只上传了表格中选择的1或3张图片。
SQL TABLE:
PHP代码:
if (isset($_GET['upload1']))
{
echo 'Skriv en kort beskrivning, ge bilden ett namn och ladda upp den här.';
echo '<form action="page.php?name=myads&upload2" enctype="multipart/form-data" method="post">';
echo 'Namn:<br />';
echo '<input type="text" name="subject" />';
echo '<br /><br />';
echo 'Kort beskrivning:<br />';
echo '<textarea name="text" style="width: 500px; height: 75px;"></textarea>';
echo '<br /><br />';
echo 'Pris:<br />';
echo '<input type="text" name="price" />';
echo '<br /><br />';
echo 'Betalning:<br />';
echo '<select name="payment">';
echo '<option>Direktbetalning</option>';
echo '<option>Swish</option>';
echo '<option>Kontant</option>';
echo '</select>';
echo '<br /><br />';
echo 'Frakt:<br />';
echo '<select name="transport">';
echo '<option>Posten</option>';
echo '<option>DHL</option>';
echo '<option>Annan</option>';
echo '</select>';
echo '<br /><br />';
echo 'Skick:<br />';
echo '<select name="condition">';
echo '<option>Ny</option>';
echo '<option>Begangnad</option>';
echo '</select>';
echo '<br /><br />';
echo 'Välj bild 1 (".jpg"):<br />';
echo '<input type="file" name="picture1" />';
echo '<br /><br />';
echo 'Välj bild 2 (".jpg"):<br />';
echo '<input type="file" name="picture2" />';
echo '<br /><br />';
echo 'Välj bild 3 (".jpg"):<br />';
echo '<input type="file" name="picture3" />';
echo '<br /><br />';
echo '<input type="submit" value="OK" />';
echo '</form>';
}
elseif (isset($_GET['upload2']))
{
$name = rand(0,99999999999);
$text = mysql_real_escape_string($_POST['text']);
$subject = mysql_real_escape_string($_POST['subject']);
$price = mysql_real_escape_string($_POST['price']);
$payment = mysql_real_escape_string($_POST['payment']);
$transport = mysql_real_escape_string($_POST['transport']);
$condition = mysql_real_escape_string($_POST['condition']);
$userid = $_SESSION['id'];
if (empty($_FILES['picture1']['name']) or empty($_FILES['picture2']['name']) or empty($_FILES['picture3']['name']) or empty($subject) or empty($text))
{ echo 'Alla fält är inte ifyllda.'; }
else
{
$explode = explode(".", $_FILES['picture1']['name']);
foreach ($explode as $exp);
$explode = explode(".", $_FILES['picture2']['name']);
foreach ($explode as $exp);
$explode = explode(".", $_FILES['picture3']['name']);
foreach ($explode as $exp);
if ($exp == 'jpg')
{
if (is_uploaded_file($_FILES['picture1']['tmp_name']))
{
if (is_uploaded_file($_FILES['picture2']['tmp_name']))
{
if (is_uploaded_file($_FILES['picture3']['tmp_name']))
{
if (move_uploaded_file($_FILES['picture1']['tmp_name'], 'uploads/photo_picture/' . $name . '.jpg'))
{ $url1 = 'uploads/photo_picture/' . $name . '.jpg'; }
if (move_uploaded_file($_FILES['picture2']['tmp_name'], 'uploads/photo_picture/' . $name . '.jpg'))
{ $url2 = 'uploads/photo_picture/' . $name . '.jpg'; }
if (move_uploaded_file($_FILES['picture3']['tmp_name'], 'uploads/photo_picture/' . $name . '.jpg'))
{ $url3 = 'uploads/photo_picture/' . $name . '.jpg'; }
else
{ die('Bilden kunde inte flyttas. Vänligen, kontakta administratören.'); }
}
}
}