Как установить путь для загрузки файла на другой URL - PullRequest
0 голосов
/ 01 сентября 2018

Я загружаю файлы на domain.com и в настоящее время сохраняю файлы по пути domain.com / upload . Но я хочу установить путь к файлу загрузки в другой глобальный каталог URL , который находится в каталоге www.domain2.com/uploads. Таким образом, мы можем хранить все наши загружаемые файлы из нескольких доменов в одном каталоге.

Вот мой upload.php

    <?php

include('../../../connect.php');

error_reporting(0);
if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {

    $appid = $_POST['appid'];

    $link_address = "../upltp.php?appid=" . $appid . "";

    //$path = "https://www.domain2.com/uploads/"; //set your folder path
    $path = "../../../uploads/"; //set your folder path
    //set the valid file extensions 
    $valid_formats = array("jpg", "png", "gif", "bmp", "jpeg", "GIF", "JPG", "JPEG", "PNG", "doc", "txt", "docx", "pdf", "PDF", "xls", "xlsx"); //add the formats you want to upload

    $name = $_FILES['myfile']['name']; //get the name of the file

    $size = $_FILES['myfile']['size']; //get the size of the file

    if (strlen($name)) { //check if the file is selected or cancelled after pressing the browse button.
        list($txt, $ext) = explode(".", $name); //extract the name and extension of the file
        if (in_array($ext, $valid_formats)) { //if the file is valid go on.
            if ($size < 30098888) { // check if the file size is more than 15 mb
                $file_name = $_POST['filename']; //get the file name
                $tmp = $_FILES['myfile']['tmp_name'];
                $imgpics =  $file_name.'.'.$ext;
                if (move_uploaded_file($tmp, $path . $file_name.'.'.$ext)) { //check if it the file move successfully.                   
                     $query = "INSERT INTO payments (app_id, imgpics) VALUES('$appid', '$imgpics') ON DUPLICATE KEY UPDATE app_id='$appid', imgpics='$imgpics'";
                     mysqli_query($connect,$query);                 
                    echo "File uploaded successfully!!
                    <br><br><a href='".$link_address."' class='butto'>Click here to Proceed to Next Step</a>";
                } else {
                    echo "failed";
                }
            } else {
                echo "File size max 15 MB";
            }
        } else {
            echo "Invalid file format..";
        }
    } else {
        echo "Please select a file..!";
    }

    exit;
}

Как мы можем установить путь к этому URL, чтобы он мог сохранять файлы из любого домена в URL пути?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...