Jump to content

uploading mp3 files to folder on server via php form..


pjc2003

Recommended Posts

hi,

 

Im trying to design a webpage form in php that allows uploading of three mp3 files to a folder on my server. The webpage should convert the name of each mp3 file uploaded to 1.mp3 , 2.mp3 and 3.mp3 and whenever a new song is uploaded it should replace whatevers in the folder on the server, im totally stuck as where to begin..

 

Any help would be great,

 

Many thanks,

 

Pete.

Link to comment
Share on other sites

try this, youl have to make a folder called uploads, in the folder where this page is saved

 

<?php
$path = "uploads/";
if (!isset($HTTP_POST_FILES['userfile'])){
echo "
<FORM ENCTYPE=multipart/form-data ACTION='' METHOD=POST>

  <p>The file:<br>
    <INPUT TYPE=file NAME=userfile>
  </p>
  <p>
    <INPUT TYPE=submit VALUE=Upload>
  </p>
</FORM>
"; }else{
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
if (($HTTP_POST_FILES['userfile']['type']=="audio/mp3")")) {
if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "<font color=red>Error</font>! The file already exists, try calling your file a different name.<br><FORM ENCTYPE=multipart/form-data ACTION='' METHOD=POST>

  <p>The file:<br>
    <INPUT TYPE=file NAME=userfile style='border: 1px solid #222222; background-color: #111111; color: #888888'>
  </p>
  <p>
    <INPUT TYPE=submit VALUE=Upload style='border: 1px solid #222222; background-color: #111111; color: #888888'>
  </p>
</FORM>"; }else{
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "upload failed!<br>"; exit; } else { echo "upload sucessful<br><br>"; }
echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>";
echo "File Path: <a href=uploads/".$HTTP_POST_FILES['userfile']['name']." TARGET=_BLANK>uploads/".$HTTP_POST_FILES['userfile']['name']."</a><br>";
echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>";
echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>";
echo "<img src=uploads/".$HTTP_POST_FILES['userfile']['name']."><br>";
}}}}
?>

Link to comment
Share on other sites

hi there, Ive created the uploads folder but its throwing up a syntax error

 

Parse error: syntax error, unexpected '"' in upload.php on line 20

 

any ideas?

 

 

 

thanks for your reply by the way its much appreciated,

 

Pjc.

 

 

 

Link to comment
Share on other sites

on line 20 i thought it was missing a "

 

 

if (($HTTP_POST_FILES['userfile']['type']=="audio/mp3")")) {

 

so ive changed it to :

 

 

if ("($HTTP_POST_FILES['userfile']['type']=="audio/mp3")")) {

 

but it now comes up with:

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /usr/home/longnines/public_html/fyp/upload.php on line 20

 

Im quite new to PHP so just after some guidance not people to do work for me.

 

Thanks.

Link to comment
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.