#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    Mesquite, TX
    Posts
    151
    Rep Power
    13

    Question Uploading MP3's with PHP


    I'm using PHP to create a dynamic RSS Feed for a friend, he's going to have the audio in MP3 format, I've gotten the file to upload on my test server, but how should I perform the user validation??

    Code is below, in case it's needed...

    Code:
    //File upload variables
    $userfile=$_FILES['userfile']['tmp_name'];
    $userfile_name=$_FILES['userfile']['name'];
    $userfile_size=$_FILES['userfile']['size'];
    $userfile_type=$_FILES['userfile']['type'];
    $userfile_error=$_FILES['userfile']['error'];
    
    if($userfile_error>0)
    {
    echo "Problem: ";
    	switch($userfile_error)
    	{
    		case 1: echo "File exceeded upload_max_filesize!"; break;
    		case 2: echo "File exceeded max_file_size!"; break;
    		case 3: echo "File only partially uploaded!"; break;		
    		case 4: echo "No file uploaded!"; break;
    	}
    	exit;
    }
    
    //Checks to ensure filetype is correct
    
    //This is the error I keep getting...
    if($userfile_type != 'audio/mpeg')
    	{
    		echo "Problem: You are attempting to upload a file that is not in the 'audio/mpeg' format!";
    		exit;
    	}
    
    /****************************************
    Find the right uploads directory!!
    ****************************************/
    $upfile='C:/uploads/'.$userfile_name;		
    
    if(is_uploaded_file($userfile))
    {
    	if(!move_uploaded_file($userfile, $upfile))
    		{
    			echo "Could not move files to destination directory";
    		}
    	echo "File uploaded successfully! <br />";
    }
    else
    {
    	echo "Possible file upload attack ".$userfile_name;
    	exit;
    }
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Posts
    4
    Rep Power
    0
    Hi,

    Your code seems to be correct... Try to check your "PHP.INI" file to insure that it allows uploading or not. And also allows to the size you upload, and the types you upload... etc.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    Mesquite, TX
    Posts
    151
    Rep Power
    13

    Question


    Thanks, I originally posted this when I was having issues with it, but I got it to upload so I'm good there.

    What I do need to know is how do I specify which users can and can't upload files?? Does it run off the FTP users, or can anyone who can get to that page upload files??
  6. #4
  7. Timelord
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2003
    Location
    Loughborough, Leicestershire
    Posts
    604
    Rep Power
    74
    sounds like you need to cross reference some users table you could setup on a database, i'd give it a field called privs and return that value to see if they are allowed up upload or not. you could store an array in there with different privs for different aspects of your application like download, upload, edit and delete etc.

    without any authentication at all anyone who hits that page will be able to upload stuff
    Andy Moore << oh no it's got a blog.....
    Over four million Legal Mp3 Downloads
    PHP developer deploying ringtones and mp3 downloads
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    Mesquite, TX
    Posts
    151
    Rep Power
    13
    resolved

    Comments on this post

    • andymoo disagrees : don't just close the post, share the solution with us.
    • bytepower disagrees : Don't just close the post, share the solution with us
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    Mesquite, TX
    Posts
    151
    Rep Power
    13
    Originally Posted by dsartain
    resolved
    Well, there really wasn't a solution as of yet...as far as the authentication goes anyway. It's a hidden page, and I just got it to do what I needed it to do without any errors, so I haven't messed with authentication yet. I'm probably just going to learn how to use SESSIONS and have some kind of control panel.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    Mesquite, TX
    Posts
    151
    Rep Power
    13
    Oh, as far as the getting it to upload goes, I think I had to rename my php.ini file to php5.ini...not sure...I was on several forums with several issues at that time..but I think that's what it was...

IMN logo majestic logo threadwatch logo seochat tools logo