php - 如何将上传文件路径设置为不同的url
问题描述
我正在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?
解决方案
推荐阅读
- kubernetes - 在 Kubernetes 中同时运行多个 pod 需要大量时间
- testing - XSL 测试错误至少包含一个而不是仅包含一个
- javascript - 如何使用 d3 仅在 y 轴上添加鼠标放大?
- sql - 求和而不计算重复值 SQL
- repository - Artifactory REST API 修改 Build Info json
- ios - 检查位置权限集
- c# - 尝试在自定义 AppDomain 中创建 C++ COM 对象的实例时出现 System.TypeLoadException
- react-360 - react-vr 集成了一个按钮用于进入 vr 模式
- c++ - std::vector::push_back() 不能在 MSVC 上为具有已删除移动构造函数的对象编译
- java - Spring Data Neo4j - findById 方法在升级到 Spring Boot 2 后抛出无效查询异常