mardi 4 avril 2017

upload a file to a specific folder php

my purpose is uploading a remote file create from my pc to specific folder,but i dont know whats wrong with it with my code below here.it uploads the file with the name and the jpg extension but not moving to the folder that i want.

   if(isset($_POST["image"]))
{



    define("SITE_NAME","project_name/"); //constant for project name
    define("SITE_PATH",$_SERVER['DOCUMENT_ROOT']."/".SITE_NAME); //constant for project base directory
    define("IMAGES_URL",SITE_URL."images/"); //constant for image directory


    $upload_base_dir=IMAGES_URL;
    $upload_time_dir=date('Y')."/".date('m')."/".date('d')."/"; // setup directory name
    $upload_dir = $upload_base_dir.$upload_time_dir;

    if (!file_exists($upload_dir)) {
        mkdir($upload_dir, 0777, true);  //create directory if not exist
    }

    $input = $_POST["image"];
    $file = fopen(time()."image.jpg", 'wb');
    fwrite($file, $input);





    //$image_name=basename($_FILES['image']['name']);
    $image=time().'_'.$image_name;
    move_uploaded_file($file,$upload_dir.$image);

    fclose($file);

}

any suggestions?thank you in advance.




Aucun commentaire:

Enregistrer un commentaire