0

hello everyone
i have a problem when i upload a song
it will not save to a folder
if i upload image then its working well but for song upload its working not well

my code is:

<?php 
include("include/commonfunction.php");
checkLogin(); 
$mode=$_REQUEST['mode'];
$tableName="songs ";
$idFieldName ="id"; 
$pid=$_GET['pid']; 
$song_url=$_REQUEST["song_url"];
$thumbnail=$_REQUEST["thumbnail"];
include("include/tophead.php");
include("fckeditor/fckeditor.php");
 function parseString($string) {
            $string = str_replace("\\", "", $string);
            $string = str_replace('/', "", $string);
            $string = str_replace('"', "".'"', $string);
            $string = str_replace("\b", "", $string);
            $string = str_replace("\t", "", $string);
            $string = str_replace("\n", "", $string);
            $string = str_replace("\f", "", $string);
            $string = str_replace("\r", "", $string);
            $string = str_replace("\u", "", $string);
             $string = str_replace("\u", "", $string);
            $string = preg_replace('/<br[^>]*>/i', '',  $string);
            $string = preg_replace('/(?:<|&lt;).+?(?:>|&gt;)/', '',  $string);

            return ''.$string.'';
    }
if($mode==2)
{   
    $sql="select * from ".$tableName ." where $idFieldName='$pid'";  
    $result=mysql_query($sql) or die (mysql_error().$sql);
    $count=mysql_num_rows($result);
    if ($count>0)
    {
        $record=mysql_fetch_array($result);
        $id             =$record['id'];
        $song_title     =$record['song_title'];
        $album_name     =$record['album_name'];
        $song_url       =$record['song_url'];
        $thumbnail      =$record['thumbnail'];
        $singer         =$record['singer'];
        $lyrics         =$record['lyrics'];
        $video_url      =$record['video_url'];
    }   
}


if(count($_POST) >0) 
{
    $id=$_POST['id'];
    $song_title=$_POST['song_title'];
    $singer=$_POST['singer'];
    $song_url=$_POST['song_url'];
    //$song_url1=$_POST['song_url1'];
    $album_name=$_POST['album_name'];
    $video_url=$_POST['video_url'];
    $lyrics=$_POST['lyrics'];
    $thumbnail=$_POST['thumbnail'];
    if($_POST['lyrics']=='')
    {
    $_SESSION['ErrorMessage']=  "Please Enter Lyrics ";
    }
    if($_POST['video_url']=='')
    {
    $_SESSION['ErrorMessage']=  "Please Enter Video Url";
    }
    if($_POST['song_title']=='')
    {
    $_SESSION['ErrorMessage']=  "Please Enter Song Title";
    }


        if ($_SESSION['ErrorMessage']=="")
        {
        if ($mode==1)
        {
        /* song upload */


            if($_FILES["song_url"]['name']!='')
            { 
                    //$fname =  explode('.',$_FILES["song_url"]['name']);
                    $fname = $_FILES['song_url']['name'];
                    $ext = pathinfo($fname, PATHINFO_EXTENSION);
                    //echo $ext = $fname[1];

                    $filen1 = uniqid().".".$ext;//$_FILES["ic_pic"]['name']; //file name
                    $path1  = 'songs/'.$filen1; //generate the destination path
                    move_uploaded_file($_FILES["song_url"]['tmp_name'],$path1);

            }  
             /* song upload */

             /* image upload */
            if($_FILES["thumbnail"]['name']!='')
            { 
                    $fname = $_FILES['thumbnail']['name'];
                    $ext = pathinfo($fname, PATHINFO_EXTENSION);
                    $filen2 = uniqid().".".$ext;//$_FILES["ic_pic"]['name']; //file name
                    $path1  = 'upload/'.$filen2; //generate the destination path
                    move_uploaded_file($_FILES["thumbnail"]['tmp_name'],$path1);

             }

              /* image upload */
        $sql="insert into  ".$tableName." set
            song_title='".mysql_real_escape_string($song_title)."',
            singer='".$singer."',   video_url='".mysql_real_escape_string($video_url)."',
            album_name='".mysql_real_escape_string($album_name)."',thumbnail='".$filen2."',
            lyrics='".mysql_real_escape_string(strip_tags($lyrics))."',
            song_url = '".$filen1."'";

            $result=mysql_query($sql) or die (mysql_error().$sql); 


            $_SESSION['SuccessMessage']=  "Recored Successfully Added!";
        }

        if ($mode==2)
        { 

         /* song upload */
        $photo_flag = 0;

            if($_FILES["song_url"]['name']!='')
            { 
                    $fname = $_FILES['song_url']['name'];
                    $ext =pathinfo($fname, PATHINFO_EXTENSION);
                    $filen1 = uniqid().".".$ext;//$_FILES["song_url"]['name']; //file name
                    // $dir=$_SERVER['DOCUMENT_ROOT'] . "/images/user_images/";  
                    $path1  = 'songs/'.$filen1; //generate the destination path
                    move_uploaded_file($_FILES["song_url"]['name'],$path1); 
                    $photo_flag =1;

            } 

            if($photo_flag==1)
            {
                $exact_photo = $filen1;
            }
            else
            {
                $exact_photo = $song_url;
            }

             /* song upload */


              /* image upload */
            $photo_flag1 = 0;

            if($_FILES["thumbnail"]['name']!='')
            { 
                    $fname = $_FILES['thumbnail']['name'];
                    $ext = pathinfo($fname, PATHINFO_EXTENSION);
                    $filen2 = uniqid().".".$ext;//$_FILES["ic_pic"]['name']; //file name
                    $path1  = 'upload/'.$filen2; //generate the destination path
                    move_uploaded_file($_FILES["thumbnail"]['tmp_name'],$path1);
                    $photo_flag1 =1;

            } 

            if($photo_flag1==1)
            {
                $exact_photo1 = $filen2;
            }
            else
            {
                $exact_photo1 = $thumbnail;
            }

             /* image upload */

        $sql="update ".$tableName." set
            song_title='".mysql_real_escape_string($song_title)."',
            singer='".$singer."',   video_url='".mysql_real_escape_string($video_url)."',
            album_name='".mysql_real_escape_string($album_name)."',
            lyrics='".mysql_real_escape_string(strip_tags($lyrics))."',thumbnail='".$exact_photo1."',
            song_url = '".$exact_photo."' where id=$pid";

            $result=mysql_query($sql) or die (mysql_error().$sql); 

            $_SESSION['SuccessMessage']=  "Recored Successfully Updated!";
        }

?>
        <script type="text/javascript">
           window.location = "viewsongs.php"
        </script>
<?php
        die(0);

}
}

?>  
 <script type="text/javascript">
var ray={
ajax:function(st)
    {
        this.show('load');
    },
show:function(el)
    {
        this.getID(el).style.display='';
    },
getID:function(el)
    {
        return document.getElementById(el);
    }
}
</script>
<style type="text/css">
#load{
position:absolute;
z-index:1; 
background:#f7f7f7;
width:300px;
height:300px;
margin-top:-150px;
margin-left:-150px;
top:50%;
left:50%;
text-align:center;
line-height:300px; 
}
</style>
</head>

<body>

<div id="wrapper">
    <?php include("include/side.php");?>
    <!-- #sidebar -->
    <div id="content">       

        <div id="contentHeader">
            <h1>Songs Information</h1> 
        </div> <!-- #contentHeader -->    

        <div class="container"> 

                <div class="grid-24">                
                    <div class="widget">          
                        <div class="widget-header">
                            <span class="icon-layers"></span>
                            <h3>Songs Information</h3>
                        </div>

                         <div> <?php include('include/status.php');?> </div>
                        <div id="main_div">
                      <form id="form1" name="form1" method="post" class="form uniformForm validateForm" autocomplete="off" enctype="multipart/form-data" onsubmit="return ray.ajax()">
                        <table width="100%" align="center" cellspacing="10">
                         <input type="hidden" id="id" name="id" value="<?php echo $id ;?>"/>  
                         <input type="hidden" id="song_url" name="song_url" value="<?php echo $song_url;?>"/>  
                          <input type="hidden" id="thumbnail" name="thumbnail" value="<?php echo $thumbnail;?>"/>  
                            <tr>
                            <td>Song Title</td>
                            <td></td>
                            <td><input type="text" name="song_title" id="song_title"  value="<?php echo $song_title;?>"  />   
                            </td>
                            </tr>
                             <tr>
                            <td>Song Thumbnail</td>
                            <td></td>
                            <td><input type="file" name="thumbnail" id="thumbnail" value="<?php echo $thumbnail;?>"  />   
                            </td>
                            </tr>
                          <tr>
                            <td>Upload Song</td>
                            <td></td>
                            <td><input type="file" name="song_url" id="song_url" value="<?php echo $song_url;?>"  />   
                            </td>
                            </tr>
                        <!--  <tr> 
                            <td>Choose one to upload song</td>
                            </tr>
                             <tr>
                            <td>Song URL</td>
                            <td></td>
                            <td><input type="text" name="song_url1" id="song_url1" value="<?php echo $song_url;?>"  />   
                            </td>
                            </tr>-->
                            <tr>
                            <td>Album Name</td>
                            <td></td>
                            <td><input type="text" name="album_name" id="album_name"    value="<?php echo $album_name;?>"  />   
                            </td>
                            </tr>

                           <tr>
                            <td>Singer</td>
                            <td></td>
                            <td><input type="text" name="singer" id="singer"    value="<?php echo $singer;?>"  />   
                            </td>
                            </tr>
                                <tr>
                                <td>Video Url</td>
                                <td></td>
                            <td><textarea cols="30" rows="5" name="video_url" id="video_url"><?php echo $video_url;?></textarea>
                            </td>
                            </tr>

                            <tr>
                                <td>Lyrics</td>
                                <td></td>
                                 <td> 
                               <textarea name="lyrics" id="lyrics" class="fieldset1"><?php echo $lyrics;?></textarea>
                                <script type="text/javascript"  src="./fckeditor/fckeditor.js"></script>
                                <script type="text/javascript">
                                          window.onload = function()
                                          {
                                              var oFCKeditor = new FCKeditor('lyrics') ;
                                              oFCKeditor.BasePath   = './fckeditor/' ;
                                              oFCKeditor.Height = 500 ;
                                              oFCKeditor.Width  = "100%" ;
                                              oFCKeditor.ReplaceTextarea() ;
                                          }
                                </script>
                                </td>
                            </tr>




                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>
                                <div id="load" style="display:none;"><img src="images/loaders/big-roller.gif"/>Loading.........Please Wait!!</div>
                                <input  type="submit" class="btn btn-primary" onclick="$('#loading').show();" name="submit" id="submit" value="Submit" />
                                </td>
                            </tr>
                        </table>
                        </form>
                      </div>

                      </div> 

                    </div>                   
                </div> <!-- .grid --> 
        </div> <!-- .container -->

    </div> <!-- #content -->


    <?php include("include/nav.php");?>

</div> <!-- #wrapper -->

<?php include("include/footer.php");?>

<script src="javascripts/all.js"></script>

</body>
</html> 
3
Contributors
3
Replies
29
Views
3 Years
Discussion Span
Last Post by almostbob
1

when sending files to the server,
the folder has to have permissions set to allow php to write to the folder
the image folder has thosee permissions set, php writes images,
Cereal asked if the songs folder is writeable
if images and songs are sent to the same folder the question is moot,

not getting the point :: may be some research to do
the host control panel helpscreens may have instructions on permissions
your ftp program likewise

Edited by almostbob

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.