Change permissions of file uploaded by PHP

前端 未结 1 1374
不知归路
不知归路 2020-12-10 12:39

I have created a small scale CMS for a website I am working on and have a form that uploads image files to be used on the website. It uploads the files successfully but the

1条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-10 13:21

    PHP Manaual chmod http://php.net/manual/en/function.chmod.php

    chmod("/somedir/somefile", 0755);
    

    In context;

    $typepath = $_POST['filetype'];
    
    $target_path = "../../images/uploads/".$typepath."/";
    
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
    
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        chmod($target_path, 0755);
        echo "

    The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded

    \n

    To the directory: ".substr($target_path, 6)."

    "; } else{ echo "There was an error uploading the file, please try again!"; }

    0 讨论(0)
提交回复
热议问题