Jump to content

PHP Upload & Adding to MYSQL


jubba890

Recommended Posts

Hi all once again! I would just like to say this forum is amazing!  :happy-04:

 

I need to upload a file to my server in /StreamIT/media/music

And in the page where you select the file I need there to be some boxes you need to fill in

Song:

Artist:

Album:

Category [This needs to be dropdown box]

Is it clean? [A yes/no type thing]

 

This needs to be on one page and I need it too add those fillouts to a MYSQL database

 

I also need a php script to get all the fields from the MYSQL database

 

 

The code I have so far: [Does not work]

 

upload_file.php

<?php
$allowedExts = array("mp3");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "mp3")
&& ($_FILES["file"]["size"] < 20000)
&& 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("music/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "music/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

And uploadm.php [Works]

<html>
<body>

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html>

I know I am asking a lot. Thank you guys!

Link to comment
https://forums.phpfreaks.com/topic/284088-php-upload-adding-to-mysql/
Share on other sites

  On 11/20/2013 at 2:19 AM, SocialCloud said:

What have you tried so far? No one is going to sit here and write it completely. The best you'll get is a template. Here's a thing to consider:

 

20000 bytes is 0.02MB (give or take). That will deny most if not all music files.

It was a test file I didnt want to upload a file that was 10MB for the sake of time. I am a newbie at this so I don't know where to start.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.