<?php

	include "/home/academi1/public_html/common_code/common_library.php";
	

    session_start();
    

    $current_folder = val( $_SESSION, "current_folder" );


    if ($current_folder == "")
    {
        echo "Error: missing current path<br>";
        exit();
    }


	if ($_FILES['file']['name'] == "")
		echo black( "No file is selected. Please go back to the Upload Files screen and click on the 'Choose File' button.<br><br>" );
	else
	{
		$filename = $_FILES['file']['name'];


		$destfile = $current_folder."/".$filename;


        if (file_exists( $destfile ))
        {
            header( "Location: /file_already_exists.php" );
            exit();
        }
        else
        {
    		if (move_uploaded_file( $_FILES['file']['tmp_name'], $destfile ))
    			chmod( $destfile, 0644 );
    		else
    		{
    			echo black( "The file that you've selected could not be uploaded" );
    			exit();
    		}
    

    		echo black( "<br>File uploaded successfully<br><br><br>" );
        }
	}


    $new_folder = urlencode( $current_folder );

	echo "<a href='folder_view.php?current_folder=".$new_folder."'>Back to previous view</a><br><br><br>";

?>