Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--- Ovo je file npr. upload.php---->
- <!-- U Istom folderu gdje je i skripta napravi file pjesme.json -->
- <!-- Kopiran upload code sa w3c i korigiran -->
- <?php
- $allowedExts = array("mpeg");
- /* Promjeni putanju */
- $putanja_do_foldera_pjesme = "stranica/pjesme/";
- $JSON = "pjesme.json";
- $temp = explode(".", $_FILES["file"]["name"]);
- $extension = end($temp);
- $nazivPjesme = $_POST["ime"];
- if (($_FILES["file"]["type"] == "audio/mpeg") && ($_FILES["file"]["size"] < 2000000) && in_array($extension, $allowedExts))
- {
- if ($_FILES["file"]["error"] > 0)
- {
- echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
- }
- else
- {
- echo "Upload: " . $_FILES["file"]["name"] . "<br>";
- echo "Type: " . $_FILES["file"]["type"] . "<br>";
- echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
- echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
- if (file_exists($putanja_do_foldera_pjesme . $_FILES["file"]["name"]))
- {
- echo $_FILES["file"]["name"] . " already exists. ";
- }
- else
- {
- move_uploaded_file($_FILES["file"]["tmp_name"], $putanja_do_foldera_pjesme . $_FILES["file"]["name"]);
- $json_content = json_decode(file_get_contents($JSON),true);
- $json_content[] = array("naziv"=>$nazivPjesme, "putanja" => $putanja_do_foldera_pjesme . $_FILES["file"]["name"] );
- file_put_contents($JSON, json_encode($json_content));
- echo "Stored in: " . $putanja_do_foldera_pjesme . $_FILES["file"]["name"];
- }
- }
- }
- else
- {
- echo "Invalid file";
- }
- ?>
- <!-- najjednostavnija forma kopirana sa w3c i korigiran -->
- <html>
- <head>
- <title>MP3 Upload</title>
- </head>
- <body>
- <form action="upload.php" method="post" enctype="multipart/form-data">
- <label for="file">Datoteka:</label>
- <input type="file" name="file" id="file"><br>
- <label for="ime">Naziv Pjesme:</label>
- <input type="text" name="ime" id="ime"><br>
- <input type="submit" name="submit" value="Submit">
- </form>
- </body>
- </html>
- <!--- OVDJE DOLAZI KOD ZA DRUGI FILE NPR. lista.php --->
- <?php
- $JSON = "pjesme.json";
- $json_content = json_decode(file_get_contents($JSON));
- $output = "<ol>";
- foreach($json_content as $content){
- foreach($content as $sadrzaj){
- echo "<li><strong>".$sadrzaj->naziv." :</strong> <a href='".sadrzaj->putanja."'>Download</a>";
- }
- }
- $output = "</ol>";
- echo $output;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment