Jump to content

PHP Upload & Adding to MYSQL


jubba890
Go to solution Solved by MDCode,

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!

Edited by jubba890
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.