Jump to content

Recommended Posts

Hey guys, i have a working image uploader but i need to convert this to a music uploader, i dont see any problems except for one line, which i dont know the equivelant from image to mp3?

 

Here is the original line:

 

if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") && 
    ($_FILES["uploaded_file"]["size"] < 1000000)) {
    
      $newname = dirname(__FILE__).'/userpics/'.$filename;

 

 

I've tried this:

 

if (($ext == "mp3") && ($_FILES["uploaded_file"]["type"] == "music/mp3") && 
    ($_FILES["uploaded_file"]["size"] < 32000000)) {
    
      $newname = dirname(__FILE__).'/music/'.$filename;

 

But all that happens is the previous pages loads for a bit (the page with the FORM on) and then doesnt forward to this page, does this mean that the file isnt even getting to this page at all?

 

I've cheked the PHP settings and theres a 32M limit so i set mine to the same...

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/141068-music-uploader/
Share on other sites

The mime type is probably audio/mp3 and in your code that is testing the ['type'], you should have an "else" statement that echoes out a meaningful user error message when the ['type'] does not have an expected value to tell you what the code is doing and that user error message should echo the value that was received so you would have immediate feedback as to why the value did not match.

Link to comment
https://forums.phpfreaks.com/topic/141068-music-uploader/#findComment-738320
Share on other sites

Cheers for the help guys, tried to test the type and still doesnt actually ever get to that page!

 

I'm uploading the file using the following Form, should work fine! Could it have something to do with our PHP server config? There are time limits etc..

 

What happens is that you choose the MP3 to upload and it thinks for a minute or two then just refreshes!

 

Here is the Form:

 

<? $user = $_GET['user']; ?>

<form enctype="multipart/form-data" action="musicuploader.php?user=<? echo "$user" ?>" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="32000000" /><br>
   <input name="uploaded_file" type="file" /><br><br>
    <input type="submit" value="Upload" />
  </form> 

 

These are the bits in the config i think are relevant:

 

(i havent missed of the units of time for the Resource limits, there isnt any!

 

Resource Limits max_execution_time 30

Resource Limits max_input_time 60

Resource Limits memory_limit 32M

File Uploads upload_max_filesize Maximum allowed size for uploaded files. 32M

 

 

 

Also there is the following text, bearing in mind i havent taken this into consideration when i coded the working image uploader???

 

where N is an integer. Instead of storing all the session files in /path, what this will do is use subdirectories N-levels deep, and store the session data in those directories. This is useful if you or your OS have problems with lots of files in one directory, and is a more efficient layout for servers that handle lots of sessions. NOTE 1: PHP will not create this directory structure automatically. You can use the script in the ext/session dir for that purpose. NOTE 2: See the section on garbage collection below if you choose to use subdirectories for session storage

 

 

Regarding the Error message, there is a message but i havent included all the code on the first post.

 

Thanks for any help!!!

 

peace

Link to comment
https://forums.phpfreaks.com/topic/141068-music-uploader/#findComment-738340
Share on other sites

The mime type might also be audio/mpeg (depends on what different browsers send).

 

Short-answer, if you have a comparison that is failing, the only way to determine why it is failing is to echo out what the value being compared actually is.

 

Link to comment
https://forums.phpfreaks.com/topic/141068-music-uploader/#findComment-738346
Share on other sites

:) cheers. The only thing is tho, the page with the comparison on isnt actually being reached! I dont think the Form is allowing the upload to the PHP temp folder. After you select the file (mp3) the page thinks for a bit then just refreshes....

 

How do i test that a file has uploaded to php temp area?

Link to comment
https://forums.phpfreaks.com/topic/141068-music-uploader/#findComment-738355
Share on other sites

Yeah, upload_max_filesize and post_max_size can both affect file uploads, so if you changed one but not the other that could be the issue.

 

A simple way to change is to add to a .htaccess file in your public_html folder:

 

php_value upload_max_filesize 32M
php_value post_max_size 32M

 

Also, for the mimetype of the file, it may also be:

 

audio/x-mp3

audio/mpeg

 

BMR777

 

Link to comment
https://forums.phpfreaks.com/topic/141068-music-uploader/#findComment-738392
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.