Trying to delete a song ;)

dj_proto87
dj_proto87
Offline
0
Hi germi! first of all thanks for this beatiful component!

See.. I was trying the last modification I need for launch my site (I´ve been working for a year, you know it very well :) )
But I got stuck in this

I need to delete the file assigned to a song (if there is already a song) and then upload the new file to be assigned to that song...
Obviously, if we are talking about a new song... nothing will be deleted, but if there is a song and that song has a file assigned to it, I want to deleted and then upload the new one..

I know the clue is the /administrator/components/com_muscol/tables/song.php

if (file_exists($path . $filename)){

$filename = time()."_".$filename;
move_uploaded_file($file["tmp_name"], $path . $filename);
chmod($path . $filename, 0777);
return $extra_path.$filename;
}
else{
move_uploaded_file($file["tmp_name"], $path . $filename);
chmod($path . $filename, 0777);
return $extra_path.$filename;
}

I use chmod to the files for them to be available to delete right?
So before the two lines move_uploaded_file... I try:

unlink($path.$this->song->filename);
and nothing...

I think the problem is not the $path... is the after $this part...
Could you help me my friend??
Responses (3)
  • Accepted Answer

    Tuesday, June 19 2012, 03:15 PM - #Permalink
    0
    I don't thinkg the chmod is necessary... have you checked that the file exists before deleting?
    The reply is currently minimized Show
  • Accepted Answer

    dj_proto87
    dj_proto87
    Offline
    Wednesday, June 20 2012, 11:35 AM - #Permalink
    0
    The chmod was necessary to be able to delete the songs.. cause I have a virtual server hosting, also a direct admin panel :S So any folder or file by default would be "apache" the owner and not "admin" or someone else owner...
    That way.. If apache is the owner, I don´t know why but I couldn´t delete the files even via ftp! So I have to change the owner manually or setting chmod to 777 ... which I did ;)

    About the post? Problem solved...
    I have to use unlink gratefully jeje...
    But the problem was I use $path when $path was another value than I need.. so I use (Jpath."/thesongfolder/".$this-filename) inside unlink and it works! Thanks Germi!!

    I have another question same as important...
    I was able to load fields belonging to the album table to model/song.php
    I mean be able to use that album fields in the songs page, for example.
    Now I would need to use fields from songs table to the album page...
    I know its the models/album.php I have to make changes, but how?


    I mean I think I have to add the fields here, in the "select" sentence... but how?? Any song table field as example would be enough ;)




    $query = ' SELECT f.*,dg.format_name as display_group_name,al.*,ar.artist_name,ar.letter,ge.genre_name '.
    ' FROM #__muscol_albums as al '.
    ' LEFT JOIN #__muscol_artists as ar ON ar.id = al.artist_id '.
    ' LEFT JOIN #__muscol_format as f ON f.id = al.format_id '.
    ' LEFT JOIN #__muscol_format as dg ON dg.id = f.display_group '.
    ' LEFT JOIN #__muscol_genres as ge ON ge.id = al.genre_id '.
    ' WHERE al.id = ' . $this->_id
    ;
    The reply is currently minimized Show
  • Accepted Answer

    Friday, June 22 2012, 07:38 PM - #Permalink
    0
    just left join the songs table and load the fields.
    The reply is currently minimized Show
Your Reply