DonJuma
DonJuma

Reputation: 2094

PHP upload file

i have been stressing for an hour at this stupid script i am trying to make it uploa an MP3 file to a folder it creates.

It is putting the information into mysql and making the folder bu when i ftp the folder is empty with no music file in there

here is the script thanks so so so much!

BTW $name is the POSTED name and full name is the posted name + ".mp3"

// BEGIN ENTERING INFORMATION TO MYSQL TABLE

$sql = mysql_query("INSERT INTO mattyc (name, date, length, size, link) 

     VALUES('$name','$date','$length','$size','$link')"
     )  or die (mysql_error());

   mkdir("../music/albums/donjuma/$name", 0777);

$song = ("../music/albums/donjuma/$name/$fullname");
        if (file_exists($song)) {
        unlink($song);
        }
        $newname = "$fullname";
        $newfile = rename(($_FILES['song']['tmp_name']),($newname));
        $place_file = move_uploaded_file( $newfile, "../music/albums/donjuma/$name/"."$newname");
        $success_msg = "<font color=\"#009900\">Your SONG has been updated, it may take a few minutes for the changes to show... please be patient.</font>";
        echo $success_msg;



    }
    }
}

Upvotes: 0

Views: 193

Answers (1)

MrWhite
MrWhite

Reputation: 45968

$newfile = rename(($_FILES['song']['tmp_name']),($newname));
$place_file = move_uploaded_file( $newfile, "../music/albums/donjuma/$name/"."$newname");

rename() returns a bool, not a filename. So your move_uploaded_file() call is going to fail. Any file renaming should be part of your move_uploaded_file() call, don't try and do anything with your temporary file apart from move it.

Upvotes: 1

Related Questions