NBS Posted September 19, 2007 Report Share Posted September 19, 2007 Zinu kā var uploadot vienu failu un pievienot datubāzei, bet kā var to izdarīt ar piem., 5 failiem ? It kā teorētiski ar kaut kādu ciklu, kuru diemžēl es praktiski nezinu. Varētu lūdzu kāds palīdzēt ? Nedaudz priekšā pateikt ? :) Link to comment Share on other sites More sharing options...
andrisp Posted September 19, 2007 Report Share Posted September 19, 2007 Ja lauki ir daži un fiksēts skaits, tad var formā vienkārši ielikt vairākus file input'us un iekš php skripta, tad katru atsevišķi apstrādāt. Link to comment Share on other sites More sharing options...
NBS Posted September 19, 2007 Author Report Share Posted September 19, 2007 $target_path = "bildes/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } $uploadedfile = $target_path; $query = "INSERT INTO `bildes` VALUES ('','$bilde')"; mysql_query($query) or die(mysql_error()); Ar šādu kodu es strādāju pirms tam viss smuki strādā vienkārši super, bet kā, lai es lieku vairākus iekšā. Link to comment Share on other sites More sharing options...
NBS Posted September 19, 2007 Author Report Share Posted September 19, 2007 Nevarētu būs kaut kas tāds: if(move_uploaded_file($_FILES['uploadedfile' && 'uploadedfile2']]['tmp_name'], $target_path)) { Link to comment Share on other sites More sharing options...
Grey_Wolf Posted September 19, 2007 Report Share Posted September 19, 2007 (edited) Ja lauki ir daži un fiksēts skaits, tad var formā vienkārši ielikt vairākus file input'us un iekš php skripta, tad katru atsevišķi apstrādāt. marazmatiski ;) prieksh kam ir domati cikli? <input type="file" name="mans[]"> ..... un pie nolasisiisanas visus izlaid caur ciklu nekaadu bedu kautch 100 faili.... Edited September 19, 2007 by Grey_Wolf Link to comment Share on other sites More sharing options...
andrisp Posted September 19, 2007 Report Share Posted September 19, 2007 Grey_Wolf, pievērs uzmanību: Ja lauki ir daži un fiksēts skaits <? function saveFile($file_input_name) { $target_path = "bildes/"; $target_path = $target_path . basename( $_FILES[$file_input_name]['name']); if(move_uploaded_file($_FILES[$file_input_name]['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES[$file_input_name]['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } $uploadedfile = $target_path; $query = "INSERT INTO `bildes` VALUES ('','$bilde')"; mysql_query($query) or die(mysql_error()); } if (forma nodota) { saveFile('file1'); saveFile('file2'); saveFile('file3'); } ?> Bet vispār jau ja faili ir vairāki par vienu, tad pats arī parasti izmantoju <input type="file" name="mans[]"> Link to comment Share on other sites More sharing options...
NBS Posted September 19, 2007 Author Report Share Posted September 19, 2007 (edited) Un ja piem., es gribētu UPDATE izmantot un man tās bildes vajag UPDATE('', '$bilde1', '$bilde2', '$bilde3') ? <? function saveFile($file_input_name) { $target_path = "bildes/"; $target_path = $target_path . basename( $_FILES[$bilde_input_name]['name']); if(move_uploaded_file($_FILES[$bilde_input_name]['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES[$bilde_input_name]['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } $uploadedfile = $target_path; $query = mysql_query('UPDATE `bildes` SET `bilde1`="'.addslashes($_POST['bilde1']).', `bilde2`="'.addslashes($_POST['bilde2']).', `bilde3`="'.addslashes($_POST['bilde3']).'" WHERE id='.$id); mysql_query($query) or die(mysql_error()); } if (forma nodota) { saveFile('bilde1'); saveFile('bilde2'); saveFile('bilde3'); } ?> Vai arī nevar šādi: $bilde_input_name Edited September 19, 2007 by NBS Link to comment Share on other sites More sharing options...
andrisp Posted September 19, 2007 Report Share Posted September 19, 2007 Tā fja katru bildi atsevišķi seivo, tāpēc arī katrai bildei atsevišķs updeits jātaisa. Un nevis $_POST, bet $_FILES masīvs ir jāizmanto. Link to comment Share on other sites More sharing options...
NBS Posted September 19, 2007 Author Report Share Posted September 19, 2007 Tā fja katru bildi atsevišķi seivo, tāpēc arī katrai bildei atsevišķs updeits jātaisa. Un nevis $_POST, bet $_FILES masīvs ir jāizmanto. <? function saveFile($file_input_name) { $target_path = "bildes/"; $target_path = $target_path . basename( $_FILES[$file_input_name]['name']); if(move_uploaded_file($_FILES[$file_input_name]['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES[$file_input_name]['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } $uploadedfile = $target_path; $query = mysql_query('UPDATE `bildes` SET `bilde1`="'.addslashes($_FILES['bilde1']).', `bilde2`="'.addslashes($_FILES['bilde2']).', `bilde3`="'.addslashes($_FILES['bilde3']).'" WHERE id='.$id); mysql_query($query) or die(mysql_error()); } if (forma nodota) { saveFile('bilde1'); saveFile('bilde2'); saveFile('bilde3'); } ?> Šādi ? if (forma nodota) { Ja es nemaldos šeit kaut kam citam jābūt. Link to comment Share on other sites More sharing options...
andrisp Posted September 19, 2007 Report Share Posted September 19, 2007 Nu protams, ka jābūt kaut kam citam. Bet kveriju tu nepareizi raksti. Tā funkcija tiek izsaukta trīs reizes. Katru reizi tā apstrādā vienu failu. Tātad arī kveriju tev vajadzētu taisīt tādu, kas apdeito konkrēto bildes lauku, nevis mēģināt visus vienā sabāzt. Link to comment Share on other sites More sharing options...
NBS Posted September 19, 2007 Author Report Share Posted September 19, 2007 Nu protams, ka jābūt kaut kam citam. Bet kveriju tu nepareizi raksti. Tā funkcija tiek izsaukta trīs reizes. Katru reizi tā apstrādā vienu failu. Tātad arī kveriju tev vajadzētu taisīt tādu, kas apdeito konkrēto bildes lauku, nevis mēģināt visus vienā sabāzt. Īsti neizpratu... Link to comment Share on other sites More sharing options...
andrisp Posted September 19, 2007 Report Share Posted September 19, 2007 (edited) Eh.. Tikko tikai arī pamanīju, ka mysql_query tu divreiz izsauc. Šī vietā: $query = mysql_query('UPDATE `bildes` SET `bilde1`="'.addslashes($_FILES['bilde1']).', `bilde2`="'.addslashes($_FILES['bilde2']).', `bilde3`="'.addslashes($_FILES['bilde3']).'" WHERE id='.$id); mysql_query($query) or die(mysql_error()); Tev vajadzētu kaut ko šādu, ja nemaldos: mysql_query('UPDATE `bildes` SET `'.$file_input_name.'`="'.addslashes($target_path).' WHERE id='.$id) or die(mysql_error()); Edited September 19, 2007 by andrisp Link to comment Share on other sites More sharing options...
NBS Posted September 19, 2007 Author Report Share Posted September 19, 2007 Eh.. Tikko tikai arī pamanīju, ka mysql_query tu divreiz izsauc. Šī vietā: $query = mysql_query('UPDATE `bildes` SET `bilde1`="'.addslashes($_FILES['bilde1']).', `bilde2`="'.addslashes($_FILES['bilde2']).', `bilde3`="'.addslashes($_FILES['bilde3']).'" WHERE id='.$id); mysql_query($query) or die(mysql_error()); Tev vajadzētu kaut ko šādu, ja nemaldos: mysql_query('UPDATE `bildes` SET `'.$file_input_name.'`="'.addslashes($target_path).' WHERE id='.$id) or die(mysql_error()); Ņja, man vajag, lai vienā tablā tas UPDATE strādātu. Man ir table piem., BILDE ID | bilde1 | bilde2 | bilde 3 Un tavs piemērs diemžēl ir galīgi garām, kā es varu: UPDATE `bildes` SET `'.$file_input_name.'`="'.addslashes($target_path).' WHERE id='.$id Failu ielikt $target_path, kas man ir folderis galīgi neloģiski ... Link to comment Share on other sites More sharing options...
andrisp Posted September 19, 2007 Report Share Posted September 19, 2007 Nu izmanto kaut vai $_FILES[$file_input_name]['name'] Link to comment Share on other sites More sharing options...
NBS Posted September 19, 2007 Author Report Share Posted September 19, 2007 Nekas man nesanāk ;( Šeit būs man smirdīgais kods: Files #1: http://paste.php.lv/6074 Files #2: http://paste.php.lv/6075 Un mans DB: http://paste.php.lv/6076 Vai kāds man normāli varētu izpalīdzēt... Link to comment Share on other sites More sharing options...
Recommended Posts