ArKos
Threadersteller
Dabei seit: 18.02.2009
Ort: Uslar
Alter: 31
Geschlecht:
|
Verfasst Mi 18.02.2009 19:14
Titel Frage zu altem Thread |
|
|
Hallo liebes Forum,
ich bin durch Google auf einen alten Beitrag gestoßen in dem ich nicht weiter komme.
HIER
Es geht darum mehrere Dateien mit einem ich nenne es mal dynamischen skript hochzuladen.
Das mit dem Felder hinzufügen klappt einwandfrei. Allerdings lädt er bei mir immer nur das 1. Bild hoch.
Kann mir da jemand helfen?
Hier noch mal mein Code
PHP-Datei:
Code: | $abfrage = "SELECT * FROM ".PREFIX."bildbestellung WHERE identify = '$identify' LIMIT 1";
$ergebnis = mysql_query($abfrage);
while($row = mysql_fetch_object($ergebnis))
{ $offer_id=$row->id; }
$maxDirSize = 50; # in Megabytes
$Email = 'mail@mail.de'; # Email to notify about upload and send URLs
$mailbody = '<html><head></head><body>';
$dirName = 'CMS/bildbestellung'; # absoluter Pfad ohne Anfangs- / mit chmod 777
$maxUploadSize = 15; # mb
$detectExtensions = '';
$acceptedExtensions = 'jpg|jpeg|png|gif|zip|rar';
$accept_ANY = 1; // Any files are allowed to be uploaded (For security, the default is 0)
$accept_jpg = 1; // jpeg image files
$accept_gif = 1; // gif image files
$accept_png = 1; // png image files
$accept_bmp = 0; // bmp image files
$accept_xbm = 0; // xbm image files
$accept_tiff = 0; // tiff image files
$accept_ico = 0; // icon image files
$accept_html = 0; // html document files
$accept_pdf = 0; // pdf document files
$accept_rtf = 0; // rtf document files
$accept_txt = 0; // txt document files
$accept_mp3 = 0; // mp3 audio files
$accept_wav = 0; // wav audio files
$accept_midi = 0; // midi audio files
$accept_aiff = 0; // aiff audio files
$accept_au = 0; // au / snd audio files
$accept_avi = 0; // avi video files
$accept_mpeg = 0; // mpeg video files
$accept_zip = 0; // zip compressed files
$accept_gzip = 0; // gzip compressed files
///////////////////////////////////////////
// Detecting server type and domain name //
///////////////////////////////////////////
$domName = str_replace('www.','',$_SERVER['SERVER_NAME']);
$moveToDir = $_SERVER['DOCUMENT_ROOT'].'/'.$dirName;
if (!file_exists($moveToDir)) die ('<h2>** CONFIGURATION ERROR **</h2><p>Directory location does not exist:</p><p>'.$moveToDir.'</p>');
if (!is_writeable($moveToDir)) die ('<h2>** CONFIGURATION ERROR **</h2><p>Permissions error (CHMOD).</p><p>Please set write permissions to:<br />'.$moveToDir.'</p>');
///////////////////////////////////////
// Collecting acceptable file types //
///////////////////////////////////////
$acceptedFileTypes = array();
$acceptedFileTypesKey = array();
if ($accept_jpg ) {
array_push($acceptedFileTypes,'image/jpeg','image/pjpeg');
array_push($acceptedFileTypesKey,'jpeg');
}
if ($accept_gif ) {
array_push($acceptedFileTypes,'image/gif');
array_push($acceptedFileTypesKey,'gif');
}
if ($accept_png ) {
array_push($acceptedFileTypes,'image/png','image/x-png');
array_push($acceptedFileTypesKey,'png');
}
if ($accept_bmp ) {
array_push($acceptedFileTypes,'image/bmp');
array_push($acceptedFileTypesKey,'bmp');
}
if ($accept_xbm ) {
array_push($acceptedFileTypes,'image/xbm','image/x-xbitmap');
array_push($acceptedFileTypesKey,'xbm');
}
if ($accept_tiff) {
array_push($acceptedFileTypes,'image/tiff');
array_push($acceptedFileTypesKey,'tiff');
}
if ($accept_ico ) {
array_push($acceptedFileTypes,'image/x-icon','image/ico');
array_push($acceptedFileTypesKey,'ico');
}
if ($accept_html) {
array_push($acceptedFileTypes,'text/html');
array_push($acceptedFileTypesKey,'html');
}
if ($accept_pdf ) {
array_push($acceptedFileTypes,'application/pdf');
array_push($acceptedFileTypesKey,'pdf');
}
if ($accept_rtf ) {
array_push($acceptedFileTypes,'text/richtext','text/rtf');
array_push($acceptedFileTypesKey,'rtf');
}
if ($accept_txt ) {
array_push($acceptedFileTypes,'text/plain');
array_push($acceptedFileTypesKey,'txt');
}
if ($accept_mp3 ) {
array_push($acceptedFileTypes,'audio/mpeg','audio/mp3');
array_push($acceptedFileTypesKey,'mp3');
}
if ($accept_wav ) {
array_push($acceptedFileTypes,'audio/wav','audio/x-wav');
array_push($acceptedFileTypesKey,'wav');
}
if ($accept_aiff) {
array_push($acceptedFileTypes,'audio/aiff','audio/x-aiff');
array_push($acceptedFileTypesKey,'aiff');
}
if ($accept_au ) {
array_push($acceptedFileTypes,'audio/basic','audio/au','audio/snd');
array_push($acceptedFileTypesKey,'au','snd');
}
if ($accept_midi) {
array_push($acceptedFileTypes,'audio/mid','audio/midi');
array_push($acceptedFileTypesKey,'mid');
}
if ($accept_avi ) {
array_push($acceptedFileTypes,'video/avi','video/x-msvideo');
array_push($acceptedFileTypesKey,'avi');
}
if ($accept_mpeg) {
array_push($acceptedFileTypes,'video/mpeg','video/mpg');
array_push($acceptedFileTypesKey,'mpeg');
}
if ($accept_zip ) {
array_push($acceptedFileTypes,'application/x-zip-compressed','application/zip');
array_push($acceptedFileTypesKey,'zip');
}
if ($accept_gzip) {
array_push($acceptedFileTypes,'application/x-gzip-compressed','application/x-gzip','application/gzip');
array_push($acceptedFileTypesKey,'gz');
}
// Check if acceptable file types have been defined
if (!count($acceptedFileTypes) && !$upload_ANY) die ('<h2>** CONFIGURATION ERROR **</h2><p>No acceptable file types have been configured.</p>');
/////////////////
// File Upload //
/////////////////
if ($_FILES['uploadfile'] && count($_FILES['uploadfile']['tmp_name'])>0) {
// Parsing acceptable extensions
if ($detectExtensions) {
$acceptedExtensions = str_replace('.','',$acceptedExtensions);
$acceptedExtArray = explode('|',$acceptedExtensions);
}
function dirsize($dir){
$totalsize=0;
$handle = @opendir($dir);
while ($file = @readdir ($handle)){
if (eregi("^\.{1,2}$",$file))
continue;
if (!is_dir($dir.$file)) {
$size=filesize($dir.$file);
$totalsize=$totalsize+$size;
}
}
@closedir($handle);
return($totalsize);
}
function echoSuccessRow($nr,$fn,$er){
global $mailbody, $dirName;
echo "<p>Upload erfolgreich für Dateinummer $nr $fn: $er </p><br />";
}
function echoFailedRow($nr,$fn,$er){
echo "<p>Upload fehlerhaft für Dateinummer $nr $fn: $er </p><br />";
}
///////////////////////////////
// Processing Uploaded Files //
///////////////////////////////
for ($k=0;$k<count($_FILES['uploadfile']['tmp_name']);$k++) {
if ($_FILES['uploadfile']['name'][$k]=='') continue;
$uploadFileNum = ($k+1).'.';
// Striping tags and invalid characters from uploaded filename
$uploadFileName = str_replace(array('|','<','>','"','\'',':','\\','/','*','?'),'',strip_tags($_FILES['uploadfile']['name'][$k]));
// Checking if uploaded file contains no data - file size is 0 bytes
if (dirsize($moveToDir.'/') > ($maxDirSize * 1024 * 1024)) {
echoFailedRow($uploadFileNum,$uploadFileName,'Serververzeichnis ist voll. Bitte versuchen Sie es zu einem anderen Zeitpunkt erneut.');
unset($_FILES['uploadfile']['tmp_name'][$k]);
continue;
}
if (filesize($_FILES['uploadfile']['tmp_name'][$k])==0) {
echoFailedRow($uploadFileNum,$uploadFileName,'Datei war 0 Byte.');
unset($_FILES['uploadfile']['tmp_name'][$k]);
continue;
}
// Detecting uploaded file for an acceptable extension
if ($detectExtensions){
$tmp = explode('.',$uploadFileName);
if (count($tmp)==1) $uploadFileExt = '';
else $uploadFileExt = $tmp[count($tmp)-1];
if (!in_array($uploadFileExt,$acceptedExtArray)){
echoFailedRow($uploadFileNum,$uploadFileName,'Datei dieses Typs nicht zulässig: .'.$uploadFileExt);
continue;
}
}
// Uploaded file error checking
switch ($_FILES['uploadfile']['error'][$k]){
case 0:
if (is_uploaded_file($_FILES['uploadfile']['tmp_name'][$k])) {
// Checking if uploaded file is an acceptable file type
if (!$accept_ANY && !in_array($_FILES['uploadfile']['type'][$k],$acceptedFileTypes)) {
echoFailedRow($uploadFileNum,$uploadFileName,'Datei dieses Typs nicht zulässig: '.$_FILES['uploadfile']['type'][$k]);
continue 2;
}
// Moving uploaded file to the configured destination directory
$moveufile = move_uploaded_file($_FILES['uploadfile']['tmp_name'][$k],$moveToDir.'/'.$uploadFileName);
// Checking if the move was successful
if ($moveufile) {
echoSuccessRow($uploadFileNum,$uploadFileName,' Status: OK');
$dateiname=$_FILES['uploadfile']['name'][$k];
$trennen=explode(".","$dateiname");
$endung=$trennen[1];
$neuername="$offer_id"."_Bild_"."$k"."."."$endung";
rename("bildbestellung/$dateiname", "bildbestellung/$neuername");
continue 2;
} else echoFailedRow($uploadFileNum,$uploadFileName,'Fehler beim verschieben der Datei in das Zielverzeichnis auf dem Server.');
} else echoFailedRow($uploadFileNum,$uploadFileName,'Datei ist keine hochgeladene Datei.');
break;
case 1:
echoFailedRow($uploadFileNum,$uploadFileName,'Datei überschreitet zulässige Server-Größe von '.ini_get('upload_max_filesize').'.');
break;
case 2:
$mfs = $_POST['MAX_FILE_SIZE'];
if ($mfs >= 1048576) $fsize = number_format($mfs/1048576,2).'MB';
else $fSize = number_format($mfs).'KB';
echoFailedRow($uploadFileNum,$uploadFileName,'Datei überschreitet zulässige Formular-Gesamtgröße von '.$fSize.'.');
break;
case 3:
echoFailedRow($uploadFileNum,$uploadFileName,'unterbrochener Dateiupload.');
break;
case 4:
break;
default:
echoFailedRow($uploadFileNum,$uploadFileName,'Ein unbekannter Fehler trat auf.');
break;
}
}
}
///////////////////////////////////
// Detecting Maximum Upload Size //
///////////////////////////////////
$umf = intval(ini_get('upload_max_filesize'));
$pms = intval(ini_get('post_max_size'));
if ($umf > $pms) $maxSize = $pms;
else $maxSize = $umf;
if ($maxSize > $maxUploadSize) $maxSize = $maxUploadSize; |
JS Datei:
Code: | // JavaScript Document
function check(){
for(var x=0; x<document.form.length; x++){
var elem = document.form.elements[x];
if((elem.name.substring(elem.name.length-2,elem.name.length)=='_r') && (elem.value=='')){
alert('Bitte alle Pflichtfelder ausfuellen!');
elem.focus();
return false;
}
}
return true;
}
function trim(str) {
return str.replace( /^\s*/, '').replace( /\s*$/, '' );
}
function AddRowsToTable() {
var tbl = document.getElementById('dateiupload');
var lastRow = tbl.rows.length;
var iteration = lastRow;
if (iteration < 10) {
var row = tbl.insertRow(lastRow);
var cellRight = row.insertCell(0);
var el = document.createElement('input');
el.setAttribute('type', 'file');
el.setAttribute('name', 'uploadfile[]');
el.setAttribute('size', '40');
cellRight.setAttribute('id',iteration)
cellRight.appendChild(el);
var aa = document.createElement("a");
aa.setAttribute('href', '#');
var clickName = new Function("DeleteRow(this)");
aa.onclick = clickName;
aa.innerHTML = " entfernen";
cellRight.appendChild(aa);
} else {
alert('Maximal 5 Dateien gleichzeitig zugelassen.');
}
}
function DeleteRow(x)
{
while (x.tagName.toLowerCase() !='tr')
{
if(x.parentElement)
x=x.parentElement;
else if(x.parentNode)
x=x.parentNode;
else
return;
}
var rowNum=x.rowIndex;
while (x.tagName.toLowerCase() !='table')
{
if(x.parentElement)
x=x.parentElement;
else if(x.parentNode)
x=x.parentNode;
else
return;
}
x.deleteRow(rowNum);
}
function RemoveRowFromTable(rowid) {
var tbl = document.getElementById(iteration);
//var lastRow = tbl.rows.length;
//if (lastRow > 1)
tbl.deleteRow(rowid);
} |
und zu letzt das Formular
Code: | <form name="form" id="form" enctype="multipart/form-data" method="post" onSubmit="return check()" action="index.php?site=offer.php&step=2">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100"><strong>Vorname: *</strong></td>
<td width="1292"><label>
<input name="vorname_r" type="text" id="vorname" value="" size="40">
</label></td>
</tr>
<tr>
<td><strong>Name: *</strong></td>
<td width="1292"><label>
<input name="zuname_r" type="text" id="zuname" value="" size="40">
</label></td>
</tr>
<tr>
<td height="10"> </td>
<td> </td>
</tr>
<tr>
<td><strong>Adresse: *</strong></td>
<td width="1292"><label>
<input name="adresse_r" type="text" id="adresse" value="" size="40">
</label></td>
</tr>
<tr>
<td><strong>PLZ/Ort: *</strong></td>
<td width="1292"><label>
<input name="plz_r" type="text" id="plz" value="" size="5" maxlength="5">
<input name="ort_r" type="text" id="ort" value="" size="30">
</label></td>
</tr>
<tr>
<td height="10"> </td>
<td> </td>
</tr>
<tr>
<td><strong>E-Mail: *</strong></td>
<td width="1292"><label>
<input name="mail_r" type="text" id="mail" value="" size="40">
</label></td>
</tr>
<tr>
<td><strong>Telefon:</strong></td>
<td width="1292"><label>
<input name="tele" type="text" id="tele" value="" size="40">
</label></td>
</tr>
<tr>
<td height="10"> </td>
<td> </td>
</tr>
<tr>
<td><strong>Format: *</strong></td>
<td><label>
<select name="format" id="format">
<option value="20_10 * 15 Glanz">10 * 15 Glanz, 20 Cent/stk.</option>
<option value="15_9 * 13 Glanz">9 * 13 Glanz, 15 Cent/stk.</option>
<option value="20_10 * 15 Matt">10* 15 Matt, 20 Cent/stk.</option>
<option value="15_9 * 13 Matt">9 * 13 Matt, 15 Cent/stk.</option>
</select>
</label></td>
</tr>
<tr>
<td><strong>Korrektur: *</strong></td>
<td><label>
<select name="korrektur" id="korrektur">
<option value="Teilkorrektur" selected="selected">Teilkorrektur</option>
<option value="Hand">Hand</option>
</select>
</label></td>
</tr>
<tr>
<td><strong>Zahlung: *</strong></td>
<td><label>
<select name="zahlung" id="zahlung">
<option value="Versand">Versand, Preis + Porto</option>
<option value="Abhohlung" selected="selected">Abhohlung</option>
</select>
</label></td>
</tr>
<tr>
<td height="10"><strong>Anmerkung:</strong></td>
<td><label>
<textarea name="anmerkung" id="anmerkung" cols="35" rows="5"></textarea>
</label></td>
</tr>
<tr>
<td height="10"> </td>
<td> </td>
</tr>
<tr>
<td><strong>AGB: *</strong></td>
<td><label>
<input type="checkbox" name="agb_r" id="agb">
Ich stimme den <a href="index.php?site=agb.php" target="_blank">AGB</a> zu.</label></td>
</tr>
<tr>
<td height="10"> </td>
<td> </td>
</tr>
<tr>
<td valign="top"> </td>
<td> <table border="0" cellspacing="2" cellpadding="2" id="dateiupload">
<tr id="row">
<td width="1" colspan="2"><input type="file" size="40" name="uploadfile[]" /></td>
</tr>
</table> </td>
</tr>
<tr>
<td> </td>
<td><table border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="178"><a href="#" onClick="AddRowsToTable();return false;">Weitere Datei hinzufügen</a></td>
<td width="148"><input type="submit" name="submit" value=" Bestellung abschicken" /></td>
</tr>
</table></td>
</tr>
<tr>
<td height="10"> </td>
<td> </td>
</tr>
<tr>
<td height="10"> </td>
<td>* = Pflichtfelder / Max. 10 Bilder gleichzeitig</td>
</tr>
</table>
</form> |
Ich vermute, dass der Fehler in der Schleife liegt, weiß aber leider nicht wo.
Bin schon am verzweifeln.
lG Arne aka ArKos
//
Ok, ich verbessser mich. Der Fehler muss im JS-liegen, da der Rest super funktionert. Sieht in vlt jemand?
Zuletzt bearbeitet von choise am Mi 18.02.2009 23:06, insgesamt 1-mal bearbeitet
|
|