Upload folder of Wordpress outside the project - php

I am trying to define the wordpress upload folder outside the installation directory. My directory structure is:
/path/to/my/base/folder
|-> wordpress (the wordpress installation)
|-> uploads (the required upload folder)
I have tried defining the 'UPLOADS' in my wp-config.php like:
define('UPLOADS', '../uploads');
Wordpress creates the folder and the images are uploaded there, but cannot use it when required. The image URL looks like :
www.myhost.dev/../uploads/image-file-name-format.jpg
But if I use absolute path to define the 'UPLOADS' like
define('UPLOADS', '/path/to/my/base/folder/uploads');
this works.
But the problem is, then the image url looks something like:
www.myhost.dev//path/to/my/base/folder/uploads/image-file-name-format.jpg
This tells the location of the file and this can be a security issue.
So, is there a better way to define the relative path for the uploads folder which will point to my required folder?
Thanks in advance.

I have done it at last by making a symlink with proper permissions. In my case, when I tried to make a symlink, the symlink did not have enough permission to write into the folder. This was because of my system (I am using Macbook). So what I did is:
$ cd wp-content
$ mv uploads /path/to/my/base/folder/
$ ln -s ../../uploads uploads
$ chmod -h 777 uploads
Check the last line where I have changed the permission for the symlink. Normally in most of the cases, you don't need to change the permission of the symlink, as they inherit the permission of the folder.

A couple of notes that may help people:
define( 'UPLOADS' , 'blah') is typically RELATIVE to the WordPress core root directory. The default is 'wp-content/uploads'. If you try to put the uploads outside of the WordPress directory with something like '../uploads/' as the define the upload URL will typically not work causing problems.
If you set the path with the define() inside your wp-config.php WordPress will NOT read the upload_path setting, if you have used it.
I found that setting the upload_path option in WordPress is better for storing media files outside the WordPress install path. Login to your WP Admin and go to the url /wp-admin/options.php to see the "raw" options list for WordPress.
Look for the upload_path setting. Put in your FULL PATH on the server like /usr/wpsite/uploads/ where /usr/wpsite/public_html would be where your WordPress core install typically ends up. Save the settings.
Your uploads will now be placed OUTSIDE the WordPress install directory. Make sure the web server has read/write permissions to the directory.
Also note that WordPress will put ALL FILES in that directory. It will not separate them into year/month subfolders as is the default for a typical WordPress install. If someone knows how to retain that feature please comment.

If you take a look at this link http://www.wpbeginner.com/wp-tutorials/how-to-change-the-default-media-upload-location-in-wordpress-3-5/
You need to use a path like so
define( 'UPLOADS', ''.'uploads' );

Related

How to chnage the uploads directory path in wordpress

I have used
define( 'UPLOADS', 'wp-content/'.'files' );
but it is only chnage the path witin wordpress folder.
I need to setup My uploads folder outsite the my C drive. I have setup the server configuration but unable to set the path in wordpress
my current path uploads directory is
C:/xampp/wordpress/wp-content/uploads
but the path is needed that
D:/images/uploads
Change Default Media Folder
Open your wp-config.php file, locoed at the root of your WordPress installation, and add the following snippet:
define('UPLOADS', 'wp-content/myimages')
Make sure you add this code before the line:
require_once(ABSPATH.’wp-settings.php’);
If the directory doesn’t already exist, WordPress will automatically create it as long as the wp-content folder is writeable. Otherwise you can great the folder yourself via FTP, cPanel etc.
You can also change the way uploads are organized. If you open your uploads folder you’ll notice that files, by default, are sorted into years. You can change your file organization so that all media files are dumped in the one folder. Go to Settings > Media and uncheck “Organize my uploads into month- and year-based folders.”
Not only will it make your URLs simpler, it will also make it easier to see all your files in one place instead of having to sort through month and year directories.

Some of the directories are accessible from public URL. How to avoid this in yii

In my Yii web application some of the directories are accessible from the public URL (main directory or application folder) like js, css, images etc. How to avoid this problem. This is a major security issue, but I don't know how to fix this. Please help me...
Thanks in advance...
If you're using Apache, you can restrict access to directories doing the following:
Create a .htaccess file in your directory so path/to/directory/to/deny/.htaccess
Open .htaccess and add Deny from all
You have to turn of apache directory listing. Use the link below.
How do I disable directory browsing?
Then change all files and folders permissions of a directory to 644 and 755.
Change all files and folders permissions of a directory to 644/755
Let me know if you need help
Here is some instructions given in documentation.
1) It's important that the directory be writable by the webserver user so that Yii can publish the resources there when needed.
2) When a project has multiple versions (production, testing, development, etc.) do not copy the assets/ folders from one area to another; allow Yii to deploy them automatically in each area.
3) Do not manually edit any file under assets/ - if you have a real need to make a change, find the publishing module, edit the source, delete the subfolder under assets/, and let Yii re-publish the updated files.
4) Do not reference names under the assets/ folder directly (say, to get at some other module's assets). If you need to use that
5) Do not add the contents of the assets/ folder to any source-code control system; these files have master source in other places.
6) It is safe to delete everything under assets/. Yii will re-publish the assets if they are not found under assets/.
Hope it will help you :)

how to include the file with relative path?

there is a file directory as this:magento\app\design\frontend\default\template\catalog\product\view.phtml
the another file directory as this:magento\blog\wp-blog-header.php
now,if i want to in view.phtml include the wp-blog-header.php.how do i do?thank you.
include('../../../../../../../wordpress/wp-blog-header.php');
You could use document root ("$_SERVER["DOCUMENT_ROOT"]"). But that only applies if your app is installed as the only app in the base directory on the web server. If you are running the app in a sub directory, that you need to adjust for that. However, this will make the app less portable as you cannot change the directory easily without having to modify codes.
Based on your example, it seems that you are running Magento, with Magento, you can use "Mage::getBaseDir" method to get the base directory of Magento and relative the include file from that.
Personally I would go from root up, not all of this ../../ jazz:
include($_SERVER['DOCUMENT_ROOT'] . "/path-to-include-file");
You sure the wordpress header is compatable with magento? Could face some horrible anomalies there.
That would work, you just have to count the slashes to make sure it's the same as before. However, you can also create a symbolic link in your magento\app\design\frontend\default\template\catalog\product\ directory that points to magento\blog\wp-blog-header.php.
ln -s magento\blog\wp-blog-header.php wp-blog-header.php would do the trick then you can just: include ("wp-blog-header.php");
You can also reference $_SERVER["DOCUMENT_ROOT"] in your include.

move_uploaded_file and relative path to destination in public_html in home directory?

I'm using OpenSuse 12.2 now. To learn and test PHP code I use public_html directory in my home folder: /home/wojtek/public_html/ I access project files in the following way:
http://localhost/~wojtek/projects/foo/bar.php
But I have not clue how to make move_uploaded_file to work. The server root is /srv/www. I set upload_tmp_dir to /srv/www/tmp (I have really no idea where it should go).
When I set destination of move_upladed_file to /srv/www/images, files landed there. But I'd like to make use of public_html folder as I'm keeping all my files there.
For example having:
public_html/projects/foo/
public_html/projects/foo/bar.php
public_html/projects/foo/images/baz.jpg
Can I somehow use the relative destination ('images/') of move_uploaded_file in the bar.php? So that I can access images relatively in IMG tag like from bar.php?
Sorry if it sounds a bit chaotic but I'm new to PHP.
No you wont be able to access the /srv/www/images folder from the /home/wojtek/public_html/projects/foo/bar.php web page.
Id suggest either
1) setting the move_uploaded_file to /home/wojtek/public_html/projects/foo/images
or
2) using a symbolic link to access the images folder from your public_html folder:
cd /home/wojtek/public_html/projects/foo
ln -s /srv/www/images/
and then it will appear that the images are stored in /home/wojtek/public_html/projects/foo/images, but they will actually still be here /srv/www/images
Its possible that you may run into trouble with permissions using this method however

put config in secure place, can not link the files

Am trying to use a config file for a database and rating script but the problem is the config file is in this directory :
website.com/include/config.php aka websitename/include/config.php
The rating script needs the config and is accessed like this:
include_once("config.php");
I want the config to be in:
"/files/website/"
A directory level up from the website root folder.
I have been trying with:
"../files/website/" and other variations but can not figure out how to link them.
I have managed to put one config file and access it, but with this ajax rating script the only way for it to work is to have the config in the /include/ folder next to:
rating_process.php - has this link : include("inc/config.php");
rating_functions.php - has this link : include_once("config.php");
rating_total_functions.php - has this link : include("inc/config.php");
Hope i've explained myself here
Right, looking at my hosting now:
$_SERVER['DOCUMENT_ROOT']; outputs this: /foldy/homepages/11/username/htdocs/webbysite
My index file is located at: /foldy/homepages/11/username/htdocs/webbysite/index.php
The included rating script is located in: /foldy/homepages/11/username/htdocs/webbysite/include/
I want the config to be in /foldy/homepages/11/username/htdocs/secretfiles/config.php
Am trying to some how go out of: webbysite folder and then into secretfiles (sibling folders)
I have tried adding ../ and so on, but am missing something obviously :(
Try
$configLocation = $_SERVER['DOCUMENT_ROOT'].'../files/website/config.php';
include_once($configLocation)
but the problem is the config file is in this directory
it is not a problem at all.
just keep it as is.
Concerning your particular problem, your problem is that you don't know where you want to put your file. /files/website/ is not likely a right path and it is apparently not one level high from webroot.
So, first of all make your mind about the right path to the directory and it's relative position to the web root
if you are concerned about security ( because your config file contains the db details ) i would place the db config file outside the site root folder and then require_once('../../dbConfig.php') from the script that's creating xml or json for your ajax
more exactly ...
your site folder might be here: /var/www/html
set a virtual host (done differently on Linux and Windows) and point your domain to a sub folder inside /html so that the new path to the site root is /var/www/html/site.
then place your config file in /var/www/html and call it from your scripts inside your /site folder using require_once('../dbConfig.php)`.
your db details are outside the site folder

Categories