Jump to content

Recommended Posts

Hi all, great forum.

 

I know how to upload images in PHP, and have a pretty decent tried and tested way of uploading securely.

 

I have not however found much when it comes to uploading music files. I have not up until recently looked into this, and was unsure about the scripting that would be done to allow this. Does anyone know of any sites that have decent toturoials or sample scripts for music uploads, or do you have any general advice? I would look to upload the music file to a directory, and then store the file name in the database to reference to.

 

The thing that I am unsure about it:

 

Making it as safe as possible, for images for example there are some decent functions that can help you abit with this, and also I actully redraw the image before uploading in my previous image uploading script.

 

I am not excatly advanced when it comes to PHP, but I am looking to learn  ;)

Link to comment
https://forums.phpfreaks.com/topic/85448-music-upload-advice-and-pointers-please/
Share on other sites

shamelessly taken from another site but hey its my 300th post.  I think I earned the right to be lazy this one time...

 

form.php

<form action="upload.php" method="post" ENCTYPE="multipart/form-data">
File: <input type="file" name="file" size="30"> <input type="submit" value="Upload!">
</form>

 

upload.php

<?php
   // ==============
   // Configuration
   // ==============
   $uploaddir = "uploads"; // Where you want the files to upload to - Important: Make sure this folders permissions is 0777!
   $allowed_ext = "mp3, wav"; // These are the allowed extensions of the files that are uploaded
   $max_size = "50000"; // 50000 is the same as 50kb

   // Check Extension
   $extension = pathinfo($_FILES['file']['name']);
   $extension = $extension[extension];
   $allowed_paths = explode(", ", $allowed_ext);
   for($i = 0; $i < count($allowed_paths); $i++) 
   {
      if ($allowed_paths[$i] == "$extension")
      {
         $ok = "1";
      }
   }

   // Check File Size
   if ($ok == "1")
   {
      if($_FILES['file']['size'] > $max_size)
      {
         print "File size is too big!";
         exit;
      }

      // The Upload Part
      if(is_uploaded_file($_FILES['file']['tmp_name']))
      {
         move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
         print "Your file has been uploaded successfully! Yay!";
      } 

      else
      {
         print "Incorrect file extension!";
      }
   }
?>

 

Code was copied / modified from this site here...

 

http://www.devpapers.com/article/41

Hi, thanks for that.

 

That checks the file extension. How safe is that for music files (as obviously anyone can add any extension to a file and upload it)? If we have this uploaded into a public directory, is there not security risks with that? 

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.