zrobiłem jak według Twoich zaleceń i mam cos takiego ale coś jest nie tak ( @ - nie miało to żadnego znaczenia czy jest czy nie efekt jest taki sam)
INSERT INTO photographs ( filename, type, size, nazwa ) VALUES ( 'carina_01.jpg', 'image/jpeg', '106767', '786') Success. INSERT INTO photographs ( filename, type, size, nazwa ) VALUES ( 'Catina_65_01.jpg', 'image/jpeg', '81895', '4675') Success. INSERT INTO photographs ( filename, type, size, nazwa ) VALUES ( '', '', '', '') Success. INSERT INTO photographs ( filename, type, size, nazwa ) VALUES ( '', '', '', '') Success. INSERT INTO photographs ( filename, type, size, nazwa ) VALUES ( '', '', '', '') Success. INSERT INTO photographs ( filename, type, size, nazwa ) VALUES ( '', '', '', '') Success.
w bazie mysql pojawia się 5 rekordów 2 z filename z linkami w filename2 nie ma nic w opisach nie ma nic w pozostałych 3 rekordach jest pusto.
A ja chciałbym żeby w jednym rekordzie pojawiały się link do zdjęć i opisy.
php
-----------------------
<?php # Upload image
for($i=0; $i <= 5; $i++) {
// Check if the form has been submitted:
if (isset($_POST['submitted'])) {
// Check for an uploaded file:
if (isset($_FILES['filename'][$i])) {
// Validate the type. Should be JPEG or PNG.
$allowed = array ('image/pjpeg', 'image/jpeg', 'image/JPEG', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png'); if (in_array($_FILES['filename']['type'][$i], $allowed)) {
// Move the file over.
if (move_uploaded_file ($_FILES['filename']['tmp_name'][$i], "../images/{$_FILES['filename']['name'][$i]}")) { echo '<p><em>The file has been uploaded!</em></p>'; } // End of move... IF.
} else { // Invalid type.
echo '<p class="error">Please upload a JPEG or PNG image.</p>'; }
} // End of isset($_FILES['upload']) IF.
@$path = $_FILES["filename"]["name"][$i];
@$type = $_FILES["filename"]["type"][$i];
@$size = $_FILES["filename"]["size"][$i];
@$nazwa = $_POST["nazwa"][$i];
//@$seria = $_POST["seria"];
//@$kod = $_POST["kod"];
//@$txt = $_POST["txt"];
//@$visible = (int) $_POST["visible"];
// przyklad - by moc wpisac 'costam' - tylko txt, nie "file" i "int"
$nazwa = mysqli_real_escape_string($connection, $nazwa);
//$seria = mysqli_real_escape_string($connection, $seria);
//$kod = mysqli_real_escape_string($connection, $kod);
//$txt = mysqli_real_escape_string($connection, $txt);
$query = "INSERT INTO photographs (";
$query .= " filename, type, size, nazwa ";
$query .= ") VALUES (";
$query .= " '{$path}', '{$type}', '{$size}', '{$nazwa}'";
$query .= ")";
$result = mysqli_query($connection, $query);
if ($result) {
// Success
} else {
// Failure
die(" Failure. " . mysqli_error
($connection));
// Check for an error:
if ($_FILES['filename']['error'][$i] > 0) {
echo '<p class="error">The file could not be uploaded because: <strong>';
// Print a message based upon the error.
switch ($_FILES['filename']['error'][$i]) {
case 1:
print 'The file exceeds the upload_max_filesize setting in php.ini.'; break;
case 2:
print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form.'; break;
case 3:
print 'The file was only partially uploaded.'; break;
case 4:
print 'No file was uploaded.'; break;
case 6:
print 'No temporary folder was available.'; break;
case 7:
print 'Unable to write to the disk.'; break;
case 8:
print 'File upload stopped.'; break;
default:
print 'A system error occurred.'; break;
} // End of switch.
} // End of error IF.
// Delete the file if it still exists:
if (file_exists ($_FILES['filename']['tmp_name'][$i]) && is_file($_FILES['filename']['tmp_name'][$i]) ) { unlink ($_FILES['filename']['tmp_name'][$i]); } // End of the submitted conditional.
}
}
}
?>
-------------------------------------
form
<form enctype="multipart/form-data"
action="photo_upload_x.php" method="post">
<input type="hidden"
name="MAX_FILE_SIZE" value="524288">
<fieldset><legend>Select a JPEG or PNG
image of 512KB or smaller to be
uploaded:</legend>
<p><b>File:</b> <input type="file"
name="filename[]" /></p>
<p>
<label for="nazwa">nazwa:</label>
<input type="text" name="nazwa[]" id="nazwa">
</p>
<p><b>File2:</b> <input type="file"
name="filename[]" /></p>
<p>
<label for="nazwa2">Nazwa2:</label>
<input type="text" name="nazwa[]" id="nazwa2">
</p>
</fieldset>
<div align="center"><input type="submit"
name="submit" value="Submit" /></div>
<input type="hidden" name="submitted"
value="TRUE" />
</form>