mp3 file upload code in php

<form class='form1' action='../inc/soundclips.php' method='post'     
                                                   enctype='multipart/form-data'>
   <input type="hidden" name="id" value="<?php echo $pid; ?>"/>
   <b>Add Soundclip For <i><?php echo $e;?></i> </b> 
   <?php echo"<divclass='editimage'>";
   echo "<img class='resizedimage' src='{$row['image']}' />";
   echo"</div>";?><br /> 
   <b>Song</b><br /><input type=text size='60' name='asong' /><br />
   <input name='file' type="file" id="file"  /><br />
   <input type='submit' name='add' value='Add Soundclip' />
</form>

0
10
Matir 130 points

                                     $allowedExts = array(&quot;mp3&quot;, &quot;jpeg&quot;, &quot;jpg&quot;, &quot;png&quot;);
 $temp = explode(&quot;.&quot;, $_FILES[&quot;file&quot;][&quot;name&quot;]);
 $extension = end($temp);

 if ((($_FILES[&quot;file&quot;][&quot;type&quot;] == &quot;audio/mp3&quot;)
        || ($_FILES[&quot;file&quot;][&quot;type&quot;] == &quot;image/jpeg&quot;)
        || ($_FILES[&quot;file&quot;][&quot;type&quot;] == &quot;image/jpg&quot;)
        || ($_FILES[&quot;file&quot;][&quot;type&quot;] == &quot;image/pjpeg&quot;)
        || ($_FILES[&quot;file&quot;][&quot;type&quot;] == &quot;image/x-png&quot;)
        || ($_FILES[&quot;file&quot;][&quot;type&quot;] == &quot;image/png&quot;))
        &amp;&amp; in_array($extension, $allowedExts))
{
   if ($_FILES[&quot;file&quot;][&quot;error&quot;] &gt; 0)
   {
      echo &quot;Return Code: &quot; . $_FILES[&quot;file&quot;][&quot;error&quot;] . &quot;&lt;br&gt;&quot;;
   }
   else
   {
      echo &quot;Upload: &quot; . $_FILES[&quot;file&quot;][&quot;name&quot;] . &quot;&lt;br&gt;&quot;;
      echo &quot;Type: &quot; . $_FILES[&quot;file&quot;][&quot;type&quot;] . &quot;&lt;br&gt;&quot;;
      echo &quot;Size: &quot; . ($_FILES[&quot;file&quot;][&quot;size&quot;] / 1024) . &quot; kB&lt;br&gt;&quot;;
      echo &quot;Temp file: &quot; . $_FILES[&quot;file&quot;][&quot;tmp_name&quot;] . &quot;&lt;br&gt;&quot;;

      if (file_exists(&quot;../soundclips/&quot; . $_FILES[&quot;file&quot;][&quot;name&quot;]))
      {
         echo $_FILES[&quot;file&quot;][&quot;name&quot;] . &quot; already exists. &quot;;
      }
      else
      {
         move_uploaded_file($_FILES[&quot;file&quot;][&quot;tmp_name&quot;],
         &quot;../soundclips/&quot; . $_FILES[&quot;file&quot;][&quot;name&quot;]);
         echo &quot;Stored in: &quot; . &quot;../soundclips/&quot; . $_FILES[&quot;file&quot;][&quot;name&quot;];
      }
   }
}
else
{
    echo &quot;Invalid file&quot;;
}

0
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source