通过PHP表单将文件上传到Github

时间:2019-05-22 18:11:38

标签: php github-api

过去几天,我尝试制作一个插入按钮,用于将文件插入包含我的网站的服务器。我的网站托管在GitHub平台上,并且我有一个PHP代码正在实现向服务器的插入。

但是,我的代码不起作用。有时我会遇到PHP文件不在同一文件夹中(上传PDF时)的问题,或者有时它只是给我一个I / O错误(发送请求)。

请帮助我。

<?php
if (isset($_POST['submit])){
    $file = $FILES['file'];


    $fileName = $_FILES['file']['name'];
    $fileTmpName = $_FILES['file']['tmp_name'];
    $fileSize = $_FILES['file']['size'];
    $fileError = $_FILES['file']['error'];
    $fileType = $_FILES['file']['type'];


    $fileEXT = explode('.', fileName);
    $fileActualExt = strtolower(end($fileExt)); 

    $allowed = array('jpg', 'jpeg', 'png', 'pdf', 'csv');

    if (in_array($fileActualExt, $allowed)) {
            if ($fileError ===0) {
                if($fileSize < 1000000) {
                        $fileNameNew = uniqid('',true).".".$fileActualExt;
                        $fileDestination = 'https://github.com/Dragos-MIHAI/2IOA0-2018-4-DBL-HTI-Webtech/tree/a861e0e8b1b546cb6eccc64926e27b7cee98b72e/'.$fileNameNew;
                        move_uploaded_file($fileTmpName, $fileDestination);
                        header("Location: index.php?uploadsucess");
                }else {
                    echo "Your file is too big!"
                }


            }else {
                echo "There was an error uploading your file!"; 
            }

    }else {
        echo "You cannot upload files of this type!";
    }

}

并在HTML中插入:

<form action="upload.php" method="POST" enctype="multipart/form-data">

        <input type="file" name="file">

        <button type ="submit" name="submit">UPLOAD</button>


        </form>

0 个答案:

没有答案
相关问题