我正在 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?