Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Uploading text message
Old 11-09-2008, 01:16 PM Uploading text message
duneglow's Avatar
Novice Talker

Posts: 10
Trades: 0
First let me say that i know absolutely nothing about php. with that in mind please I have this one code that uploads a song it works just great the only problem is that there is no message saying to the user that the file is being uploaded.

Could someone please help me add the ability to show "UPLoading" while the file is being uploaded?

here is the file upload code:

Code:
<?php
define("IN_SECURE", TRUE);
require(dirname(__FILE__)."/common.php");
//$username = "developer";

$upload_path = $usercontent."/".$username."/";
$upload_url = $contenturl."/".$username."/";

$action = isset($_POST['act'])?$_POST['act']:(isset($_GET['act'])?$_GET['act']:'add');
$song_id = isset($_POST['song_id'])?$_POST['song_id']:(isset($_GET['song_id'])?$_GET['song_id']:0);
$song_id = (int)$song_id;

if($action=='edit' && $song_id)
{
    if($_POST)
    {
        //TODO : Validation
        $_POST = db_escape($_POST);

        $sql = "UPDATE songs SET "
                ." song_title = '".$_POST['song_title']."',"
                ." song_album_id = '".$_POST['song_album_id']."',"
                ." song_username = '".$username."',"
                ." song_url = '".$_POST['song_url']."'"
                ." WHERE song_username='".$username."' AND song_id=".$song_id;

        mysql_query($sql) or die(mysql_error());

        header("Location: songs.php");
        exit();
    }
    else
    {
        $sql = "SELECT * FROM songs WHERE song_username='".$username."' AND song_id =".$song_id;
        $res = mysql_query($sql);
        $record = mysql_fetch_assoc($res);
    }
}
elseif($action=='add' && $_POST)
{
    $err = "";
    if(!$_FILES['song_filename']['tmp_name'])
    {
        $err = "Mp3 file not selected or error uploading file";
    }

    if(!$err)
    {
        $_POST = db_escape($_POST);

        $filename = clean(preg_replace('/\.mp3$/', '', $_FILES['song_filename']['name']));
        $ext = ".mp3";
        while(file_exists($upload_path.$filename.$ext))
        {
            $filename .= $filename."_";
        }

        $filename .= $ext;
        if(move_uploaded_file($_FILES['song_filename']['tmp_name'], $upload_path.$filename))
            chmod($upload_path.$filename, 0666);

        $sql = "INSERT INTO songs (song_album_id, song_username, song_title, song_filename, song_url)"
                . " VALUES ("
                . "'".$_POST['song_album_id']."', "
                . "'".$username."', "
                . "'".$_POST['song_title']."', "
                . "'".$filename."', "
                . "'".$_POST['song_url']."'"
                . ")";

        mysql_query($sql);

        header("Location: songs.php");
        exit();
    }
    else
    {
        $record = $_POST;
    }
}
elseif($action=='del' && $song_id)
{
    $sql = "SELECT * FROM songs WHERE song_username='".$username."' AND song_id =".$song_id;
    $res = mysql_query($sql);
    $r = mysql_fetch_assoc($res);

    if($r)
    {
        @unlink($upload_path.$r['song_filename']);
        $sql = "DELETE FROM songs WHERE song_username='".$username."' AND song_id =".$song_id;
        $res = mysql_query($sql);
    }

    header("Location: songs.php");
    exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//Dtd html 4.0 Transitional//EN">
<html>
<HEAD>
<TITLE>Music Catalog</TITLE>
<SCRIPT language=javascript>
function validform() {
    var msg ='';

    if (document.form1.song_filename)
    {
        if (document.form1.song_filename.value== '') { msg+='Song File is required \n';}
        if (document.form1.song_filename.value!= ''){
            var ext = document.form1.song_filename.value;
            ext = ext.substring(ext.length-3,ext.length);
            ext = ext.toLowerCase();
            if(ext != 'mp3') { msg+='Please upload only .mp3 file \n';}
        }
    }

    if (document.form1.song_title.value== '')     { msg+='Title is required \n';}


     if (msg!=='') {
         message='Following fields are missing ! \n\n';
        message+=msg;
        alert(message);
        return false;
    } else {
        return true
    }
}
</SCRIPT>
<LINK href="style.css" type=text/css rel=stylesheet>
</HEAD>
<body bgColor=#ffffff leftmargin="10" rightmargin="10">
<table cellSpacing=2 cellPadding=1 width=603 border=0>
  <tbody>
    <tr>
      <td align=middle bgColor=#b7eaff height=25><span class="style15 style26"><a href="songs.php">Manage Songs</span></td>
      <td align=middle bgColor=#b7eaff height=25><span class="style15 style26"><a href="albums.php">Manage Albums</span></span></td>
    </tr>
  </tbody>
</table>
<form id="form1" name="form1" action="songs.php" onSubmit="return validform();" method="post" enctype="multipart/form-data">
  <table cellSpacing=1 cellPadding=1 width=603 border=0>
    <tbody>
      <tr>
        <td align=middle bgColor=#b7eaff colSpan=2 height=25><span class="style15 style26">Upload Song</span></td>
      </tr>
      <?php
      if($err)
      {
      ?>
      <tr>
        <td colSpan=2><font color=#ff0000><?=$err?></font></td>
      </tr>
      <?php
      }

      if($action!='edit')
      {
      ?>
      <tr>
        <td class=style6><font color=#ff0000>* </font>Song:</td>
        <td>
          <input class=style6 id=song_filename type=file name=song_filename>
        </td>
      </tr>
      <?php
      }
      ?>
      <tr>
        <td class=style6><font color=#ff0000>* </font>Song Title:</td>
        <td>
          <input class=style6 id=song_title size=40 name=song_title value="<?=$record['song_title']?>">
        </td>
      </tr>
      <tr>
        <td class=style6>Song Album:</td>
        <td class=style6>
          <select class=style6 name=song_album_id>
            <option value="" selected>None</option>
            <?php
            $sql = "SELECT * FROM albums WHERE album_username='".$username."' ORDER BY album_name";
            $res = mysql_query($sql);
            while($r = mysql_fetch_assoc($res))
            {
                if($record['song_album_id']==$r['album_id'])
                    echo '<option value="'.$r['album_id'].'" selected="selected">'.$r['album_name'].'</option>';
                else
                    echo '<option value="'.$r['album_id'].'">'.$r['album_name'].'</option>';
            }
            ?>
          </select>
        </td>
      </tr>
      <tr>
        <td class=style6>Shopping URL:</td>
        <td>
          <input class=style6 id=song_url size=40 name=song_url value="<?=$record['song_url']?>">
        </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>
          <input type=hidden name=song_id value="<?=$record['song_id']?>">
          <input type=hidden name=act value="<?=$action?>">
          <input class=button type=submit value=Submit name=Submit>
          <input class=button id=Reset type=reset value=Reset name=Reset>
        </td>
      </tr>
    </tbody>
  </table>
</form>
<table cellSpacing=0 cellPadding=0 width=603 border=0>
  <tbody>
    <tr>
      <td align=middle bgColor=#b7eaff colSpan=3 height=25><span class="style15 style26">You Uploaded Songs</span></td>
    </tr>
    <tr>
      <td>
        <table cellSpacing=2 cellPadding=2 width="100%" border=0>
          <tbody>
            <tr>
              <td width=200 class=style5 bgColor=#b7eaff>Song Title</td>
              <td class=style5 width=140 bgColor=#b7eaff>Album</td>
              <td class=style5 width=83 bgColor=#b7eaff>Preview</td>
              <td width=141 bgColor=#b7eaff></td>
            </tr>
            <?php
            $sql = "SELECT * FROM songs"
                    . " LEFT JOIN albums ON song_album_id=album_id"
                    . " WHERE song_username='".$username."' ORDER BY album_name, song_title";

            $res = mysql_query($sql) or die(mysql_error());
            while($r = mysql_fetch_assoc($res))
            {
            ?>
            <tr bgColor=#f2f2f2>
              <td class=style6 bgColor=#f2f2f2><?=$r['song_title']?></td>
              <td class=style6 bgColor=#f2f2f2><?=($r['song_album_id']?$r['album_name']:"None")?></td>
              <td class=style6 bgColor=#f2f2f2>
                <OBJECT id=wimpy_button_1
                        codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,47,0
                        height=15 width=15
                        classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000
                        name=wimpy_button01>
                  <PARAM NAME="movie" VALUE="<?=$wimpy_url?>/button.swf?theFile=<?=$upload_url.$r['song_filename']?>">
                  <PARAM NAME="quality" VALUE="high">
                  <PARAM NAME="wmode" VALUE="transparent">
                  <EMBED
                        src="<?=$wimpy_url?>/button.swf?theFile=<?=$upload_url.$r['song_filename']?>"
                        quality=high WIDTH="15" HEIGHT="15"
                        NAME="wimpy_button01"
                        TYPE="application/x-shockwave-flash"
                        PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
                  </EMBED>
                </OBJECT>
              </td>
              <td class=style6 bgColor=#f2f2f2>
                <a class=style6 href="songs.php?act=edit&song_id=<?=$r['song_id']?>">Edit</a> /
                <a class=style6 href="songs.php?act=del&song_id=<?=$r['song_id']?>" onClick="return confirm('Are you sure?');">Delete</a>
              </td>
            </tr>
            <?php
            }
            ?>
          </tbody>
        </table>
      </td>
    </tr>
  </tbody>
</table>
</body>
</html>

and this is te CSS style for the above code


Code:
.style5 {
    FONT-WEIGHT: bold; FONT-SIZE: 10px; COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
}
A.style5:link {
    COLOR: #666666; TEXT-DECORATION: none
}
A.style5:visited {
    COLOR: #666666; TEXT-DECORATION: none
}
A.style5:hover {
    COLOR: #000000; TEXT-DECORATION: underline
}
A:visited {
    COLOR: #666666; TEXT-DECORATION: none
}
A:hover {
    COLOR: #000099; TEXT-DECORATION: underline
}
A:active {
    COLOR: #000099; TEXT-DECORATION: none
}
A:link {
    COLOR: #666666; TEXT-DECORATION: none
}
.style6 {
    FONT-SIZE: 10px; COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
}
A.style6:link {
    COLOR: #666666; TEXT-DECORATION: none
}
A.style6:visited {
    COLOR: #666666; TEXT-DECORATION: none
}
A.style6:hover {
    COLOR: #000000; TEXT-DECORATION: underline
}
.button {
    BORDER-TOP-WIDTH: 1px; BORDER-LEFT-WIDTH: 1px; FONT-SIZE: 11px; BORDER-BOTTOM-WIDTH: 1px; WIDTH: auto; FONT-STYLE: normal; FONT-FAMILY: Arial, Helvetica, sans-serif; HEIGHT: 20px; BACKGROUND-COLOR: #b7eaff; TEXT-ALIGN: center; BORDER-RIGHT-WIDTH: 1px
}
.style15 {
    FONT-WEIGHT: bold; FONT-SIZE: 12px; COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
}
.style26 {
    COLOR: #000000
}
.border {
    BORDER-RIGHT: #cccccc 1px solid; BORDER-TOP: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; BORDER-BOTTOM: #cccccc 1px solid
}
thank you so much
__________________
Pain is weakness leaving the body

Please login or register to view this content. Registration is FREE
duneglow is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-11-2008, 01:46 PM Re: Uploading text message
Extreme Talker

Posts: 246
Trades: 3
This is probably not the best way to do it, but it is certainly one way:

First, start learning some PHP. It is fun, and will come in handy when making changes/additions to existing PHP scripts.

Second, take a look at the following PHP progress bar. http://www.phpbuilder.com/columns/wh...r20060912.php3
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
CouponGuy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Uploading text message
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22460 seconds with 12 queries