1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help on Uploading Code

Discussion in 'PHP' started by caspermz, Apr 6, 2009.

  1. #1
    Hello i have this uploading code working but i would like to add an status bar or something that says how much % of upload goes.

    I really dont know how to do it can someone help me this is my code:
    /********** Upload Song **********/
    
    	function songupload()
    	{
    		global $HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_SERVER_VARS,$HTTP_SESSION_VARS,$HTTP_COOKIE_VARS;
    
    		$page = $HTTP_GET_VARS['page'];
    
    		switch( $page ) {
    		case 'approve':
    
    			$this->approveupload_Song(($HTTP_GET_VARS['id']));
    			break;
    		case 'deny':
    			$this->denyupload_Song(($HTTP_GET_VARS['id']));//infoupload_Song('deny');
    			break;
    		default:	// default new
    			$this->infoupload_Song('new');
    			break;
    		}
    
    		//print("<h1>Add Multiple Files</h1>");
    		print("<br><p><a href='?action=songlink&show=5&type=Songs' style='font-weight:bold'>Add Songs Download Link.</a>");
    	}
    	function infoupload_Song($type)
    	{
    		global $HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_SERVER_VARS,$HTTP_SESSION_VARS,$HTTP_COOKIE_VARS,$HTTP_POST_FILES;
    
    		$id = ($HTTP_GET_VARS['id']);
    
    		print("<div id='info'>\n");
    		// Save Information?
    		if( $HTTP_GET_VARS['save'] == 'yes' ) {
    
    			 $susername = $HTTP_SESSION_VARS["username"];
    			 $suserid = $HTTP_SESSION_VARS["userid"];
    			if( $type == 'new' )
    			{
    				$sfalg = 1;
    			 $susername = $HTTP_SESSION_VARS["username"];
    			 $suserid = $HTTP_SESSION_VARS["userid"];
    
    			for($i=0;$i<5;$i++)
    			{
    				$str_upload		=	trim(basename($HTTP_POST_FILES["upload_song_path".$i]["name"]));
    				$spath = trim($HTTP_POST_FILES["upload_song_path".$i]["name"]);
    ///aaa				
    
    				
    				
    
    ///aaaa
    				if($HTTP_POST_VARS['song_name'.$i] != "")
    				{
    					$str_size = $HTTP_POST_FILES["upload_song_path".$i]["size"];
    					$str_user_id = $HTTP_SESSION_VARS["userid"];
    		//echo("<br>".$str_size);
    					if($str_size < 20000000)
    					{
    						// check songname  and filename alredy exist or not
    						$str_0 = "select * from upload_song where song_name = '".(trim($HTTP_POST_VARS['song_name'.$i]))."'";
    						$result_0 = @mysql_query($str_0);
    						$rows_0 = @mysql_num_rows($result_0);
    						if($rows_0 == 0)
    						{
    							$str_1 = "select * from upload_song where song_path = '".$spath."'";
    							$result_1 = @mysql_query($str_1);
    							$rows_1 = @mysql_num_rows($result_1);
    							if($rows_1 == 0)
    							{
    									//**********	Insert into Db ( upload_song table )	******************
    								$query = "INSERT INTO upload_song ( song_name, artist_name, album_name, format_id, song_path ,user_name) VALUES ";
    								$query .= "('".(trim($HTTP_POST_VARS['song_name'.$i]))."','Soundzet','Uploaded Songs','".trim($HTTP_POST_VARS['format_id'.$i])."','".$spath."','".$susername."')";
    								$rs = @mysql_query($query);
    										//**********		Upload Song	******************
    								$UPLOAD_PATH = AUDIO_DIR."/";//"audio/";
    								if(is_uploaded_file($HTTP_POST_FILES["upload_song_path".$i]["tmp_name"]))
    								{
    									move_uploaded_file($HTTP_POST_FILES["upload_song_path".$i]["tmp_name"],$UPLOAD_PATH.$str_upload);
    								}
    								//print("<p> ".($i+1).") Upload the song successfully </p>");
    								$toggle = 1;
    								$arr_song_name[] = (trim($HTTP_POST_VARS['song_name'.$i]));
    							}
    							else
    							{
    									$arr_song_name[] = "<font color = '#0000FF'><b>".(trim($HTTP_POST_VARS['song_name'.$i])) . "</b></font><br>Unable to uplaod the song.... Song with file already exists" ;
    
    							/*	$toggle = 10;	// File Name Already exists
    								break;
    							//	print("<p> ".($i+1).")  Unable to uplaod the song ........<br> Song with file name '".$spath."' already exists</p>");*/
    							}
    						}
    						else
    						{
    								$arr_song_name[] = "<font color = '#0000FF'><b>".(trim($HTTP_POST_VARS['song_name'.$i]))."</b></font> <br> Unable to uplaod the song.... Song name already exists" ;
    
    						}
    					}
    					else
    					{
    							$arr_song_name[] = "<font color = '#0000FF'><b>".(trim($HTTP_POST_VARS['song_name'.$i]))."</b></font> <br> Unable to uplaod the song.... File Size Must be less than 20 Mb" ;
    
    					}
    				}
    			}
    				/************************************************************/
    			} else {
    				$query = "UPDATE song SET song_name = '".($HTTP_POST_VARS['song_name'])."', artist_id = '8', album_id='6', format_id='".$HTTP_POST_VARS['format_id']."', song_path='".($HTTP_POST_VARS['song_path'])."' WHERE id = '".$id."'";
    			}
    
    
    
    		if($toggle == 1)
    		{
    			//print("<p> Success! We were able to upload the songs</p>");
    		}
    		else
    		{
    			//print("<p> Warning! We were unable to upload the songs</p>");
    		}
    
    		}
    
    		// Determine Type of Form
    		if( $type == 'new' ) {
    		    print("<title>".PGTITLE."</title>");
    			print("<META NAME='Keywords' CONTENT='Upload Songs'>
    <META NAME='Description' CONTENT='Upload Songs'>
    <meta name='robots' content='all,index,follow' />
    <meta name='msnbot' content='all,index,follow' />
    <meta name='googlebot' content='index,noarchive,follow,noodp' />
    <META NAME='Author' CONTENT='sales@musicboxv2.com'>");
    			print("<table cellpadding='0' cellspacing='0' class='moduletable'><tr><td class='title_class' valign='top'>Upload Songs</td></td></tr></table>\n");
    			print("<center>You can upload 5 songs at once - The Upload can take a while</center><br>\n");
    			$song_name = "";
    			$artist_id = "8";
    			$album_id = "6";
    			$length_min = 0;
    			$length_sec = 0;
    			$format_id = "";
    			$song_path = $this->musicpath;
    		} else {
    
    			print("<h1>Edit Song</h1>\n");
    			$query = "SELECT * FROM song WHERE id = '".$id."'";
    			$row = mysql_fetch_assoc( mysql_query($query) );
    
    			$song_name = $row['song_name'];
    			$artist_id = $row['artist_id'];
    			$album_id = $row['album_id'];
    			$length_min = floor($row['length']/60);
    			$length_sec = $row['length']%60;
    			$format_id = $row['format_id'];
    			$song_path = $row['song_path'];
    
    		}
    		print( "<style>.para {	font-family: verdana, sans-serif;font-size:8pt;color:'black';text-decoration:none;}</style>");
    		if($sfalg==1)
    			{
    				print(" <b>Following songs uploaded successfully </b><br><br>");
    				print("<table border ='0'>");
    				//print("<tr><td><b> Song Name </b></td></tr>");
    				for($j=0;$j<count($arr_song_name);$j++)
    				{
    					print("<tr><td><li>".$arr_song_name[$j]."</li></td></tr></table>");
    				} 
    			}
    		// Form
    		print '
    		<script>
    		function validForm()
    		{
    			var cnt = 0;
    			for(i=0;i<5;i++)
    			{
    				var tb = ("document.form1.upload_song_path")+i;
    				var frmName = "form1";
    				txt = eval(tb).value;
    				
    				if(txt == "")
    					cnt++;
    				else
    				{
    					if(!ValidUplodFileType(frmName, tb, "Please Enter Valid File Type"))
    						return false;
    				}	
    			}
    			
    			if(cnt == 5)
    			{
    				alert("Please Enter Atleast One Section Information To Upload Your Song...!");
    				return false;
    			}
    			else
    			{
    				return true;
    			}
    			return true;
    		}
    		
    		</script>
    		';
    		$query = "SELECT * FROM format";
    		$format = mysql_query($query);
    		
    		while($format_row = mysql_fetch_assoc($format))
    		{
    			$format_rows[] = $format_row;
    		}
    		for($i=0;$i<count($format_rows);$i++)
    		{
    			if($i != count($format_rows)-1)
    				$coma = ",";
    			else
    				$coma = "";
    			$allowed_song_format .= $format_rows[$i]['extension'].$coma;
    		}
    		print("<form action='?action=upolad_songs&page=".$type."&save=yes&id=".$id."' method='post' name='form1' id='form1' enctype = 'multipart/form-data' onsubmit='return validForm()'>\n");
    		print "<input type=hidden name=allowed_song_format_cnt value ='".count($format_rows)."'>";
    		for($i=0;$i<count($format_rows);$i++)
    		{
    			print "<input type=hidden name=allowed_song_format$i value ='".$format_rows[$i]['extension']."'>";
    		}
    //print("<font color = 'red' size = '2' >File size must be less than 20 Mb<br><br></font>");
    		
    		print("<table border='0' cellpadding='5' cellspacing='5'>\n");
    		print "<tr><td colspan=2><strong>Valid Upload Song File Type: $allowed_song_format </strong></td></tr>";
    		for($vloop=0;$vloop<4;$vloop++)
    		{
    			print("<center><tr>\n");
    			print("<td><font size='2'> <b>Song and Artist Name</b>: </font></td>");
    			print("<td><input class = 'para' name='song_name$vloop' type='text' id='song_name$vloop' maxlength='255' size = '20'></td></tr>\n");
    			print("<td><font size='2'>Format:</font></td>\n");
    			/*print("<td><input class = 'para' name='format_id$vloop' id='format_id$vloop' type='text'  maxlength='255' size = '15' ></td></tr>\n");*/
    			print("<td><select class = 'para' name='format_id$vloop' id='format_id$vloop'>\n");
    			$query = "SELECT * FROM format ORDER BY format ASC";
    			$result = mysql_query($query);
    			while( $row = mysql_fetch_assoc($result) ) {
    				print("<option value='".$row['id']."' ".(($row['id']==$format_id)?'SELECTED':'').">".$row['format']."</option></center>\n");
    			}
    			print("<center></select></td></tr>\n");
    			print("<td><font size='2'>Song Path: </font></td>\n");
    			print("<td><input class = 'para' name='upload_song_path$vloop'  type='file'></td></tr></table><br><table></center>\n");
    			print("\n");
    			}
    			print("<center><tr>\n");
    			print("<td colspan = '10'>\n");
    			print("&nbsp;</td>\n");
    			print("</tr>\n");
    			print("<tr>\n");
    			print("<td colspan = '10' align = 'middle' ><input name='Submit'  type='submit' class='year' id='Submit' value='Submit'>\n");
    			print("<input name='Reset' type='reset'  class='year' id='Reset' value='Reset'>\n");
    			print("</td>\n");
    			print("</tr></table>\n"); 
    			print("</form>Once you Upload a Song This Song will Appear in the Next 24hs</p>\n");
    			print("</div></center>\n");
    		
    		
    	}
    
    PHP:
    Thank you alot :D
     
    caspermz, Apr 6, 2009 IP
  2. codealot

    codealot Banned

    Messages:
    544
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    All you need is a gif scrolling image while the upload is occurring in the backroung. No need to modify the code.
     
    codealot, Apr 7, 2009 IP
  3. caspermz

    caspermz Active Member

    Messages:
    152
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    68
    #3
    but that will show you the real progress?
     
    caspermz, Apr 7, 2009 IP
  4. octalsystems

    octalsystems Well-Known Member

    Messages:
    352
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    135
    Digital Goods:
    1
    #4
    octalsystems, Apr 8, 2009 IP