Can someone take a look at this code?

  • Qsic
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Mar 30, 2005
  • Posts: 35
  • Status: Offline

Post August 16th, 2006, 3:14 pm

The problem I am having is uploading mp3's. A friend of mine fixed this once and said that the problem was that the code said it could only upload wav files. Now it's not working again and I think for some reason it went back to the old version. Now when I try to upload an mp3 it says you must upload an mp3. You can go to http://www.misslerecords.com and look for youself. Anyways here is the code. Thank you to whoever can help.

PHP Code: [ Download ] [ Select ]
<?
 
 
 
$f = $_FILES['song'];
 
 
 
$pp = $_REQUEST;
 
 
 
if (($f['type'] == "application/octet-stream" || $f['type'] == "audio/mpeg") && strpos($f['name'], '.mp3')) {
 
   if ($f['error'] == false) {
 
      $name = str_replace(array(' ', '"', "'", ',', '.', '/', '\\', '?', "\t", "\n"), '_', $f['name']) . '.mp3';
 
      $result = move_uploaded_file($f['tmp_name'], "./music/$name");
 
      if (!$result) {
 
         $message = "<li>An error occurred while moving your song into the music folder. This is probably an error with our systems. Please try your submission again later.";
 
      }
 
   } else {
 
      $message = '<li>The following error occurred while uploading: ' . $f['error'];
 
   }
 
} else {
 
   $message = "<li>You must upload an MP3 song!";
 
}
 
 
 
if ($message) {
 
   $message = "<ul>$message</ul>";
 
   $url = "step3.php?";
 
   foreach($pp as $key => $value) {
 
      $url .= "$key=$value&";
 
   }
 
   $url .= "message3=$message";
 
   header("Location: $url");
 
} else {
 
   $valid = "fnamelnameaddresszipcitystateagreeemailbandartworktitle";
 
 
 
   foreach ($pp as $key => $value) {
 
      if (strpos($valid, $key) !== false) {
 
         $$key = stripslashes($value);
 
      }
 
   }
 
   
 
   $now = date ("g:i m/d/y");
 
     
 
   require('db.php');
 
   
 
   $result = mysql_query("insert into data (fname, lname, bandname, email, address, city, state, zip, title, songfile, imgfile, date)
 
            values ('$fname', '$lname', '$band', '$email', '$address', '$city', '$state', '$zip', '$title', '$name', '$artwork', '$now')");
 
 
 
   if (!$result) {
 
      echo "Failed inserting information to database!";
 
   }
 
   
 
   mail ('Jacob <jsattleen@gmail.com>', 'Missle Records Song Submission', "Hey Jacob! Another band named '$band' submitted a song to the site! Click the link below
 
   to see details on this submission!\r\n\r\nhttp://www.qsic.net/uploadform/review.php?p=23n8nd339djdj93dj", "From: Missle Records <nobody@qsic.net>");
 
}
 
?>
 
 
 
 
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 
"http://www.w3.org/TR/html4/strict.dtd">
 
 
 
<html>
 
 
 
<head>
 
   <title>Your Title Here</title>
 
   <style type="text/css">
 
      body {
 
         background-color: #999;
 
         font: 12pt Arial;
 
      }
 
     
 
      div#cFloat {
 
         margin: 25px auto;
 
         padding: 10px;
 
         border: 1px Solid #666;
 
         color: #333;
 
         background-color: #ccc;
 
         font: inherit;
 
         text-align: center;
 
         width: 500px;
 
      }
 
     
 
      i {
 
         font-size: 80%;
 
      }
 
     
 
      a {
 
         color: #a04;
 
         text-decoration: none;
 
      }
 
     
 
      a:hover, a:active {
 
         text-decoration: underline;
 
      }
 
   </style>
 
   
 
</head>
 
 
 
<body>
 
 
 
   <div id="cFloat">
 
   Submit Your Music to Missle Records: <i>(finished)</i><br><br>
 
   <b>Thanks for your submission!</b><br>
 
   We will review your submission and contact you shortly!<br>
 
   <br>
 
   <a href="/">Main</a>
 
   </div>
 
 
 
</body>
 
 
 
</html>
  1. <?
  2.  
  3.  
  4.  
  5. $f = $_FILES['song'];
  6.  
  7.  
  8.  
  9. $pp = $_REQUEST;
  10.  
  11.  
  12.  
  13. if (($f['type'] == "application/octet-stream" || $f['type'] == "audio/mpeg") && strpos($f['name'], '.mp3')) {
  14.  
  15.    if ($f['error'] == false) {
  16.  
  17.       $name = str_replace(array(' ', '"', "'", ',', '.', '/', '\\', '?', "\t", "\n"), '_', $f['name']) . '.mp3';
  18.  
  19.       $result = move_uploaded_file($f['tmp_name'], "./music/$name");
  20.  
  21.       if (!$result) {
  22.  
  23.          $message = "<li>An error occurred while moving your song into the music folder. This is probably an error with our systems. Please try your submission again later.";
  24.  
  25.       }
  26.  
  27.    } else {
  28.  
  29.       $message = '<li>The following error occurred while uploading: ' . $f['error'];
  30.  
  31.    }
  32.  
  33. } else {
  34.  
  35.    $message = "<li>You must upload an MP3 song!";
  36.  
  37. }
  38.  
  39.  
  40.  
  41. if ($message) {
  42.  
  43.    $message = "<ul>$message</ul>";
  44.  
  45.    $url = "step3.php?";
  46.  
  47.    foreach($pp as $key => $value) {
  48.  
  49.       $url .= "$key=$value&";
  50.  
  51.    }
  52.  
  53.    $url .= "message3=$message";
  54.  
  55.    header("Location: $url");
  56.  
  57. } else {
  58.  
  59.    $valid = "fnamelnameaddresszipcitystateagreeemailbandartworktitle";
  60.  
  61.  
  62.  
  63.    foreach ($pp as $key => $value) {
  64.  
  65.       if (strpos($valid, $key) !== false) {
  66.  
  67.          $$key = stripslashes($value);
  68.  
  69.       }
  70.  
  71.    }
  72.  
  73.    
  74.  
  75.    $now = date ("g:i m/d/y");
  76.  
  77.      
  78.  
  79.    require('db.php');
  80.  
  81.    
  82.  
  83.    $result = mysql_query("insert into data (fname, lname, bandname, email, address, city, state, zip, title, songfile, imgfile, date)
  84.  
  85.             values ('$fname', '$lname', '$band', '$email', '$address', '$city', '$state', '$zip', '$title', '$name', '$artwork', '$now')");
  86.  
  87.  
  88.  
  89.    if (!$result) {
  90.  
  91.       echo "Failed inserting information to database!";
  92.  
  93.    }
  94.  
  95.    
  96.  
  97.    mail ('Jacob <jsattleen@gmail.com>', 'Missle Records Song Submission', "Hey Jacob! Another band named '$band' submitted a song to the site! Click the link below
  98.  
  99.    to see details on this submission!\r\n\r\nhttp://www.qsic.net/uploadform/review.php?p=23n8nd339djdj93dj", "From: Missle Records <nobody@qsic.net>");
  100.  
  101. }
  102.  
  103. ?>
  104.  
  105.  
  106.  
  107.  
  108.  
  109. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  110.  
  111. "http://www.w3.org/TR/html4/strict.dtd">
  112.  
  113.  
  114.  
  115. <html>
  116.  
  117.  
  118.  
  119. <head>
  120.  
  121.    <title>Your Title Here</title>
  122.  
  123.    <style type="text/css">
  124.  
  125.       body {
  126.  
  127.          background-color: #999;
  128.  
  129.          font: 12pt Arial;
  130.  
  131.       }
  132.  
  133.      
  134.  
  135.       div#cFloat {
  136.  
  137.          margin: 25px auto;
  138.  
  139.          padding: 10px;
  140.  
  141.          border: 1px Solid #666;
  142.  
  143.          color: #333;
  144.  
  145.          background-color: #ccc;
  146.  
  147.          font: inherit;
  148.  
  149.          text-align: center;
  150.  
  151.          width: 500px;
  152.  
  153.       }
  154.  
  155.      
  156.  
  157.       i {
  158.  
  159.          font-size: 80%;
  160.  
  161.       }
  162.  
  163.      
  164.  
  165.       a {
  166.  
  167.          color: #a04;
  168.  
  169.          text-decoration: none;
  170.  
  171.       }
  172.  
  173.      
  174.  
  175.       a:hover, a:active {
  176.  
  177.          text-decoration: underline;
  178.  
  179.       }
  180.  
  181.    </style>
  182.  
  183.    
  184.  
  185. </head>
  186.  
  187.  
  188.  
  189. <body>
  190.  
  191.  
  192.  
  193.    <div id="cFloat">
  194.  
  195.    Submit Your Music to Missle Records: <i>(finished)</i><br><br>
  196.  
  197.    <b>Thanks for your submission!</b><br>
  198.  
  199.    We will review your submission and contact you shortly!<br>
  200.  
  201.    <br>
  202.  
  203.    <a href="/">Main</a>
  204.  
  205.    </div>
  206.  
  207.  
  208.  
  209. </body>
  210.  
  211.  
  212.  
  213. </html>
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post August 16th, 2006, 3:14 pm

  • vision
  • Beginner
  • Beginner
  • User avatar
  • Joined: May 20, 2004
  • Posts: 58
  • Loc: Maryland
  • Status: Offline

Post August 16th, 2006, 6:40 pm

Quote:
if (($f['type'] == "application/octet-stream" || $f['type'] == "audio/mpeg") && strpos($f['name'], '.mp3')) {


Is the error message you get when you try and upload that you can only upload MP3 files?

Your checking type is audio/mpeg is that right? I thought mpeg was for video... but perhaps that is right.

Also, I suspect if you upload something called MYSONG.MP3 it will fail. If your on a unix box (not sure about windows) you are only looking for .mp3 so if the filename is upper case it would fail.
  • champi0n
  • Graduate
  • Graduate
  • User avatar
  • Joined: May 05, 2006
  • Posts: 200
  • Status: Offline

Post August 17th, 2006, 9:07 pm

Your error is in
Code: [ Download ] [ Select ]
if (($f['type'] == "application/octet-stream" || $f['type'] == "audio/mpeg") && strpos($f['name'], '.mp3')) {


did you set upload_max_filesize?

Maybe try something similar to:
Code: [ Download ] [ Select ]
    if( is_uploaded_file($_FILES[inputname][tmp_name]) )
        move_uploaded_file( $_FILES[inputname][tmp_name], "/music/{$_FILES[inputname][name]}" );
    else $_FILES[inputname][name] = 'none';


  $sql="INSERT INTO yourtable VALUES ('{$_FILES[inputname][name]}', ....)";

  $rs=mysql_query($sql);
  1.     if( is_uploaded_file($_FILES[inputname][tmp_name]) )
  2.         move_uploaded_file( $_FILES[inputname][tmp_name], "/music/{$_FILES[inputname][name]}" );
  3.     else $_FILES[inputname][name] = 'none';
  4.   $sql="INSERT INTO yourtable VALUES ('{$_FILES[inputname][name]}', ....)";
  5.   $rs=mysql_query($sql);
[PHP SOURCE CODE ENCRYPTION SOFTWARE] -- Protect your valuable source code!
Add product licensing to your encrypted php scripts, expiry dates and locking to specific ip's or domains.
Protect. Lock. Distribute.
  • Rabid Dog
  • Cheese Monkey
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3188
  • Loc: South Africa
  • Status: Offline

Post August 19th, 2006, 12:30 pm

I remember IE having a problem, or was it only able to accept (can't remember) with application/octet-stream

The headers that the browser uses need to be checked.
My Software Development Company
Music I have recorded (fixed now :))
Image

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: kingdutka and 211 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2010 Unmelted, LLC. Driven by phpBB © 2010 phpBB Group.