Ok so this is my server structure...
ROOT
-PUBLIC_HTML
--IMAGES
-SUBDOMAIN
As you can see, the subdomain is located on the root alongside the public_html.
How can i upload a file from the subdomain (subdomain.site.com) to the public_html/images (site.com/images) folder? or is this not possible?
Thanks.
When you upload your file just have your move_uploaded_file() move the file to the desired location in the main domain's directory.
If you're using open_basedir make sure you have rights to write to your main domain's directories.
Added the example code below - you will have to tweak it to make it work for you
The easiest way is to use an absolute path. You could use something like this
// let's assume your upload code is here: /var/www/subdomain.mysite.com/my-upload-code.php
// your desired location
$myImageDir = '/var/www/mysite.com/my-images/' ;
$fileName = basename($_FILES['pictures']['name']) ;
move_uploaded_file($_FILES['pictures']['tmp_name'], $myImageDir . $fileName) ;
In my case my sub domain and main domain were both inside the public_html.
public_html:
sub domain
uploads
uploading happens in sub domain. So in my file path variable I just added ../
ex: $path = "../uploads"
to go outside the current directory from subdomain to maindomain.
Related
I work in responsivefilemanager and in config file I Have two line:
$upload_dir = '/user/uploads/files/'; // path from base_url to base of upload folder (with start and final /)
$current_path = '../../../../uploads/files/'; // relative path from filemanager folder to upload folder (with final /)
This wroked In xammp system (with sub folder. /user/ is sub folder). if i move in real server i need to edit this two line and remove sub folder and one ../ from two line.
Now, I need to auto detect url path. My mean is : if i install in sub folder Or root folder this two line worked in my script without manual editing.
How do can i create this?
There is no particular way to just autodetect what directory to upload to. The easiest is to solve this by just checking if the directory exists and use the other directory if it was not found.
However, I'd suggest having the same relative structure on both systems is the best solution. With the same relative structure this should work across all servers and systems without having to change anything.
Is it possible to include file from the ftp's root in a script in a subdomain ?
This doesn't work for me:
include($_SERVER['DOCUMENT_ROOT'].'/joomla.php');
Can someone help me ?
I think first you need to determine where is your subdomain files are placed and echo the $_SERVER['DOCUMENT_ROOT'] command to see the full path then you can combine two paths and make necessary adjustments.
Usually but not always, subdomain files are placed in a folder one level up then the main site's root folder so you may need to replace the folder name according to your needs in the output of server document folder function.
To give an example if your domain files are in a path like
/var/www/vhosts/example.com/httpdocs/
and if your subdomain path is like
/var/www/vhosts/example.com/subdomain/
then you will need to replace httpdocs with subdomain (or the other way around) in the output where you call $_SERVER['DOCUMENT_ROOT']
public_html/(root)index.php
/image/123.jpg
/subdomain(root)/upload.php
I have file upload.php can upload image, this file is locate in sub-domain folder (I have set sub-domain folder as another root)
I need to upload image to main domain, /image/ (image's folder)
however I could not find the right path. I have try ../ but it wont work above the root
anyone know how to solve this problem?
Use path like /home/content/html/images
I have a website with the following path for images: domain.com/images
I am using a PHP script in the back-end to upload images to that folder BUT the page that lets me upload images to that path above is located at domain.com/administration/upload.php.
So now when I am using a script to write to domain.com/images this is what I am using:
$newname="/images/".$image_name;
For some reason it won't write to that folder and I get no errors and here's the link from where I got the script:
http://www.reconn.us/content/view/30/51/
What do I have to do to make it write to that domain.com/images path from domain.com/administration/upload.php?
You have to distinguish virtual server path from filesystem path.
There are no /images/ directory on your disk
but something like /home/www/user/public_html/images/
so, change your code to
$newname = $_SERVER['DOCUMENT_ROOT']."/images/".$image_name;
and it should be okay
You can try this for the exact path to folder
/* $_SERVER['DOCUMENT_ROOT'] will point to your root folder( www ) and after that your website folder name and them images folder name */
$newname = $_SERVER['DOCUMENT_ROOT']."/folder name/".$image_name;
I have a php function that is moving files for me. It requires absolute paths to place those files (/Applications/MAMP/HTdocs/mysite/myfolder)
how can a turn this folder path string into a url (http://mysite.com/myfolder) so that I can create links to the files on the fly?
I do not know necessarily the names of the folders, as the software could be run in many locations.
Many thanks.
Obviously, you need to know server root for such a calculation.
Luclikly, $_SERVER['DOCUMENT_ROOT'] contains this path.
So, just subtract server root path from the given path:
$path = '/Applications/MAMP/HTdocs/mysite/myfolder';
$approot = substr($path,strlen($_SERVER['DOCUMENT_ROOT']));
check if you have a drive letter in the DOCUMENT_ROOT, and correct the code if necessary
Note that adding http://mysite.com is unnecessary and useless. just /myfolder/ is what you really need.
You can check for this value: $_SERVER["DOCUMENT_ROOT"];
That is the root of your website. If you have the folder and replace the $_SERVER["DOCUMENT_ROOT"] with the $_SERVER["HTTP_HOST"] you will get the URL to the folder/file
If mysite folder is within HTdocs then you can access it using http://yourdomain/mysite, (if HTodcs is your home directory)