每天都学一点

php网页上传文件到Ubuntu服务器(input type=fire)- 赖大大

01 03月
作者:林健|分类:Ubuntu
直接上代码:
<form enctype="multipart/form-data" method="post" action="">
    <input type="file" name="myfile" accept=".xls,.doc,.txt,.pdf,.ppt,.mp4">
    <br>
    <input type="submit" value="上传" name="save" >
</form>
php:
header("content-type:text/html;charset=utf-8");
if(isset($_POST["save"])){
    $filename = $_FILES["myfile"]["name"];
    $type = $_FILES["myfile"]["type"];
    $tmp_name = $_FILES["myfile"]["tmp_name"];
    $size = $_FILES["myfile"]["size"];
    $error = $_FILES["myfile"]["error"];
    $path = "/upload";
    if(!file_exists($path)){
        if(!mkdir($path,0777))
            echo "创建文件夹失败!";
    }
    $date = date("Ymdhis");
    $filename = $date.".".pathinfo($filename)['extension'];
    $path.="/".$filename;
    if(is_uploaded_file($tmp_name)){
        if(move_uploaded_file($tmp_name,$path)){
            echo "<script>
                alert('文件上传成功!');
                </script>";
        }else{
            die("上传文件失败!");
        }
    }else{
        die("不是一个上传文件!");
    }
}
把代码运行,在本地是可以上传,但是把代码上传到服务器上后,发现却没办法上传,什么原因呢?

我通过winSCP连接服务器,在服务器上创建了upload的文件夹,但也上传不了

主要是权限问题,服务器上的文件夹是带有小锁的,没有读写的权限。

进入远程服务器:
输入: chmod -R 777 /upload
其中最后的参数是文件夹名字。

 

文件就可以上传到服务器的指定文件夹了!


    浏览2 评论0
    返回
    目录
    返回
    首页
    U盘上安装Ubuntu系统 便捷式系统 - 赖大大 ubuntu 16.04服务器安装apache2 + php + mysql

    发表评论