ziedinjsh Posted May 3, 2011 Report Share Posted May 3, 2011 Sveiki! Ir tāda lieta, ka nesaprotu ka pēc nevar augšupielādēt failu. if(isset($_POST['addSong'])){ $target = "mp3/"; $target = $target . basename( $_FILES['mp3']['name']) ; $ok=1; //This is size condition if ($mp3_size > 167772160) { echo "Your file is too large.<br>"; $ok=0; } //This is limit file type condition if ($mp3_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //File type alowed if (!($mp3_type=="audio/mpeg, audio/x-mpeg, audio/mp3, audio/x-mp3, audio/mpeg3, audio/x-mpeg3, audio/mpg, audio/x-mpg, audio/x-mpegaudio")) { echo "You may only upload MP3 files.<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['mp3']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['mp3file']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } } echo "<form method='POST' action='".$_SERVER['PHP_SELF']."'>"; echo "Song title <input type='text' name='title' class=''>"; echo "Type <select name='type'>"; echo "<option value='1'>Standart</option>"; echo "<option value='2'>Experimental</option>"; echo "</select>"; echo "Song file <input type='file' name='mp3' class=''>"; echo "<input type='submit' name='addSong' value='Add song' class=''>"; echo "</form>"; Kad augšupielādēju fails nav folderā un rādās sekojoš teksts:You may only upload MP3 files. Sorry your file was not uploaded. Kapēc viņš neatpazīst mp3 failu? bez file type atpazīšanas rādās šāds teksts:Sorry, there was a problem uploading your file. php.ini nomainīju augšupielādes izmēra limitu uz 200mb, nesaprotu kapēc neiet Paldies jau iepriekš! Quote Link to comment Share on other sites More sharing options...
briedis Posted May 3, 2011 Report Share Posted May 3, 2011 (edited) Debugot vajag. Izdrukā $_FILES masīva saturu (kam tad tāds print_r() domāts??), paskaties vai vispār jebkas tiek uploadots. Formai trūkst atribūta enctype="multipart/form-data" Edited May 3, 2011 by briedis Quote Link to comment Share on other sites More sharing options...
Lauris Posted May 3, 2011 Report Share Posted May 3, 2011 Kas tas par joku - if (!($mp3_type=="audio/mpeg, audio/x-mpeg, audio/mp3, audio/x-mp3, audio/mpeg3, audio/x-mpeg3, audio/mpg, audio/x-mpg, audio/x-mpegaudio")) { ? Un kur vispār tiek uzsetots $mp3_type ? Quote Link to comment Share on other sites More sharing options...
briedis Posted May 3, 2011 Report Share Posted May 3, 2011 Njā, uzmetot aci kodam paliek bēdīgi. Par identāciju arī neesi neko dzirdējis? Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted May 3, 2011 Author Report Share Posted May 3, 2011 šo joku if (!($mp3_type=="audio/mpeg, audio/x-mpeg, audio/mp3, audio/x-mp3, audio/mpeg3, audio/x-mpeg3, audio/mpg, audio/x-mpg, audio/x-mpegaudio")) aizvācu. Briedis enctype="multipart/form-data" neko nemainīja Array ( [title] => [type] => 1 [mp3] => D7 - Cave.mp3 [addSong] => Add song ) Quote Link to comment Share on other sites More sharing options...
briedis Posted May 3, 2011 Report Share Posted May 3, 2011 Nu ok, ja jau tas neko nemainīja tad vāc viņu nost, paskatīšos kā tad augšuplādēsi kaut vienu failu ;) Problēma ir tajā, ka tev nav ne mazākās nojausmas, kas tur notiek tajā kodā, jo neesi rakstījis pats nevienu rindiņu... Quote Link to comment Share on other sites More sharing options...
Rincewind Posted May 3, 2011 Report Share Posted May 3, 2011 Kur mainīgie tiek definēti? $mp3_size/$mp3_type Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted May 3, 2011 Author Report Share Posted May 3, 2011 tādu kodu es internetā atradu, jo pats es īsti nemāku izveidot! Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted May 3, 2011 Report Share Posted May 3, 2011 No shit... Tieshaam 3 gadi nav gana ilgs laiks lai maaceetu kaut ko jau uzrakstiit? Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted May 3, 2011 Author Report Share Posted May 3, 2011 kaut ko bišķ jau var, bet ar šo nenodarbojos regulāri Quote Link to comment Share on other sites More sharing options...
daGrevis Posted May 3, 2011 Report Share Posted May 3, 2011 Ne visi ir spējīgi veikt "lielu lēcienus". Labākais, ka vismaz mēģini, ir to darīt pa mazām daļām un jā... būtu tā kā jāsaprot kas tur notiek, kāpēc notiek, kam, vispār, ir jānotiek... 1) Izveidojam HTML formu, kas var sūtīt failus (briedis jau minēja), 2) Pārbaudām, vai forma aiziet (tiek "submitted"), 3) No masīva $_FILES paņemam failu un saglabājam to kāda servera mapē, 4) Pieliekam validāciju (tur faila izmērs, paplašinājums, viss ko sirds kāro); P.S. Man lielais lēciens bija no PHP uz Java. Tagad taisu "Space Invaders" spēli. Quote Link to comment Share on other sites More sharing options...
kapec gan ne Posted May 3, 2011 Report Share Posted May 3, 2011 if(isset($_POST['addSong'])) { $target = "./mp3/"; $target = $target . basename($_FILES['mp3']['name']); $ok= false; if ($_FILES['mp3']['size'] > 167772160) { $ok = "Your file is too large.<br>"; } if(!$ok) { if(!move_uploaded_file($_FILES['mp3']['tmp_name'], $target)) { $ok .= "Sorry, there was a problem uploading your file.<br/>"; } } if(!$ok) { echo "The file ". basename( $_FILES['mp3']['name']). " has been uploaded!<br/>"; } else { echo $ok; } } echo "<form method='POST' action=''enctype='multipart/form-data'>"; echo "Song title <input type='text' name='title' class=''>"; echo "Type <select name='type'>"; echo "<option value='1'>Standart</option>"; echo "<option value='2'>Experimental</option>"; echo "</select>"; echo "Song file <input type='file' name='mp3' class=''>"; echo "<input type='submit' name='addSong' value='Add song' class=''>"; echo "</form>"; extension pats parbaudi. kam title domāts? :) Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted May 3, 2011 Author Report Share Posted May 3, 2011 (edited) nu tā man ir sanācis šitā: if(isset($_POST['addmp3'])){ $folder = "mp3/"; $title = $_POST['title']; $type = $_POST['type']; $song = $_FILES['mp3']['name']; $size = $_FILES['mp3']['size']; $tmp = $_FILES['mp3']['tmp_name']; $date = date('y.m.d'); $mp3 = $folder.basename($_FILES['mp3']['name']); if($type == "audio/mp3" || $size >167772160) { die("this format is not allowed or file is to big"); } else { $query = mysql_query("INSERT INTO songs (song, size, title, type, date) VALUES ('$song', '$size', '$title', '$type', '$date') "); move_uploaded_file($_FILES['mp3']['tmp_name'], $mp3); echo "mp3 uploaded!"; } } echo "<form method='post' action='".$_SERVER['PHP_SELF']."' enctype='multipart/form-data'>"; echo "<input type='text' name='title'>"; echo "<select name='type'><option value='1'>Normal</option><option value='2'>Experimental</option></select>"; echo "<input type='file' name='mp3'>"; echo "<input type='submit' name='addmp3' value='Add'>"; echo "</form>"; Bet protams mp3 fails netiek augšupielādēts.. un datubāzē size arī rāda 0 es nevaru iebraukt kas pa vainu P.S. mp3 failu nevar augšupielādēt, bet bilžu faili augšupielādējas.. kapēc tā? Edited May 3, 2011 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
briedis Posted May 3, 2011 Report Share Posted May 3, 2011 Tak paskaties ko pats esi sarakstījis: if($type == "audio/mp3" || $size >167772160) { die("this format is not allowed or file is to big"); } Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted May 3, 2011 Author Report Share Posted May 3, 2011 audio/mp3 nomainīju uz audio/mpeg Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.