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.

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>";
}}}}
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.