请如何在我的主域名目录中存储上传的文件,如下所示:
move_uploaded_file(https://example.com/uploads)
答案 0 :(得分:0)
这将是一种快速而肮脏的方法(假设您位于子域的根目录中,而您的主域是其自己的文件夹(如果您的主目录没有自己的文件夹,则删除第2个CHDIR)
我假设您正在上传图片。如果没有必要进行更改
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^' to uri 'home/index.php'
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^' to uri 'home/index.php'
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '(.*)' to uri 'home/index.php'
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^(admin|ajax|assets|blocks|cache|classes|Connections|cron|editor|inc|intranet|lang|loops|pub|webassist)($|/)' to uri 'home/index.php'
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^(/home/)?$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^sfogliabile/([\\d]+).htm$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^depliant/([\\d]+).htm$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.251836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^([a-z]+)/risultati.htm$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^([a-z]+)/cookie.htm$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^([a-z]+)/nojs.htm$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^([a-z]+)/3/([\\w-]+)/$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^([a-z]+)/3/([\\w-]+)/([\\d]+)/([\\w-]+).htm$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^([a-z]+)/4/([\\w-]+)/$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^([a-z]+)/4/([\\w-]+)/([\\d]+)/([\\w-]+).htm$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^([a-z]+)/5/([\\w-]+)/$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^([a-z]+)/5/([\\w-]+)/([\\d]+)/([\\w-]+).htm$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^([a-z]+)/6/([\\w-]+)/$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^([a-z]+)/6/([\\w-]+)/([\\d]+)/([\\w-]+).htm$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^([a-z]+)/([\\w-]+)/([\\d]+)/([\\w-]+).htm$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^([a-z]+)/$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '^(.*)$' to uri 'home/index.php'
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] strip per-dir prefix: D:/Web/ljpharma/home/index.php -> home/index.php
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace3] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] applying pattern '(^|/)\\.' to uri 'home/index.php'
[Sat Jul 08 16:05:15.252836 2017] [rewrite:trace1] [pid 28420:tid 1232] mod_rewrite.c(477): [client 127.0.0.1:51317] 127.0.0.1 - - [ljpharma.dev/sid#2ee51d8][rid#4ec1ee0/initial] [perdir D:/Web/ljpharma/] pass through D:/Web/ljpharma/home/index.php
如果您使用的是php 7,您可能需要查看字符串
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
答案 1 :(得分:0)
第一步是从这里开始处理上传的文件:
http://php.net/manual/en/function.move-uploaded-file.php
第一个例子几乎就是你想要的:
<?php
$uploads_dir = '/uploads';
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
// basename() may prevent filesystem traversal attacks;
// further validation/sanitation of the filename may be appropriate
$name = basename($_FILES["pictures"]["name"][$key]);
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
}
?>
您需要进行两次修改。 $uploads_dir
需要具有文件上传位置的相对路径。我们假设您的表单位于subdomain.example.com/
中子域的根目录中,并且您希望将其移至public_html/uploads
。您的新$uploads_dir
应如下所示:
$uploads_dir = __DIR__ . '/../public_html/uploads';
__DIR__
将为您提供运行php文件的当前导演。这允许您创建到其他目录的相对路径。
第二个编辑是更新$_FILES
数组,以循环显示正在上传的内容的正确结构。它可能不是示例中的图片。