Relative paths when uploading image with Symfony 1.4 on shared hosting - symfony-1.4

I've had a running website on VPS which I've built using Symfony 1.4.20 but then I decided to move it to a shared hosting and the problems arised. I think I've done the essential parts since it's accesible now but when I try to upload any images via backend it shows error message as in the ss below:
Failed to create file upload directory "/../public_html/img".
img folder, which I try to upload the image into, is already created and inside the public_html folder. I also set public_html and img folders' chmod as 777.
When I use the url_for function it shows the correct url of images from public_html/img folder, for example: domain/img/imagename.png
Here's my configuration:
/
/app (Everything except web folder is here)
/public_html (I put everything inside the web folder into this folder)
My ProjectConfiguration.class.php file:
require_once dirname(__FILE__).'/../lib/vendor/symfony-1.4.20/lib/autoload/sfCoreAutoload.class.php';
public function configureDirectories()
{
sfConfig::set('sf_web_dir', '/../public_html');
sfConfig::set('sf_all_images_url', '/img');
sfConfig::set('sf_all_images_dir', sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . 'img');
}
And in my backend.php:
require_once(dirname(__FILE__).'/../app/config/ProjectConfiguration.class.php');
So when I want to save any image I give the relative path like this:
$filepathImage = sfConfig::get('sf_all_images_dir') . '/' . $filenameImage;
It used to work back in the day when my website is configured as default on the private server but now I'm stuck, I need to fix this as soon as possible, so please help me :) I didn't do any url rewriting. If you need further information about any part of the project I can show it. Thanks.

maybe you need to dump ur $filepathImage and see if it's the right path

Related

Uploads in Symfony's var directory not accessible

I'm trying to upload files into 'var' directory (successfully). But when I want to take this one file from 'var' I only can observe No route found for "GET /var/uploads/images/....
Structure:
- app
- bin
- src
- var
- cache
- logs
- uploads
- images
- vendor
- web
For saving my files I'm using: '%kernel.project_dir%/var/uploads/images'
For order to take file: '/var/uploads/images/' . $fileName;
Where're my mistake?
P.S. Moreover I try to use volume (I'm using docker) in my docker-compose file like this: - ./data/cabinet/uploads/images:/data/www/cabinet/var/uploads/images
And, unfortunately, no one file didn't copy to this directory. What's wrong?
Thank you!
Since the document root is pointing to the web directory, there's no possibility for path ../var to be accessible. Either store uploads inside the web directory or create a symlink inside it pointing to the var/data/uploads:
// since I don't know your path tree inside the container
// I assume whole application is installed inside /var/www/html
// and this is the default working directory
docker-compose exec YOUR_CONTAINER_NAME \
ln -rs /var/www/html/var/data web/var
Bear in mind that if you are using Apache webserver, the FollowSymLinks option has to be enabled, but most probably is.
As for the second question, most likely you mapped an invalid directory, I guess this should be:
// yet again I assume whole application is inside the /var/www/html
./data/cabinet/uploads/images:/var/www/html/data/cabinet/uploads/images
Is this some kind of production anyway? If it is not and this is merely a work-in-progress, then you rather should map your whole local directory as container volume. This is how it's usually done in dev mode, so the mapping would be:
.:/var/www/html

Locating local directory for localhost

I've been spending hours trying to locate where localhost's files are stored.
I've tried looking at the page source but all it tells me is http:/localhost/....
which is not what I need.
My Xampp directory (where I load Xampp control) is located in my desktop but there is no change when I alter stuff inside its htdocs.
The default root for XAMPP, assuming you installed in the default location, is c:\xampp\htdocs. You can change this by modifying the Apache configuration in c:\xampp\apache\conf\httpd.conf.
You can always check it through PHP:
echo $_SERVER["DOCUMENT_ROOT"];
Or if you want to use WordPress functions:
echo get_stylesheet_directory();
Include these codes in your page.php or header.php for example.

"Unable to create directory wp-content/uploads" in wordpress?

I encountered this problem when I am trying to upload image files to my wordpress. I am using XAMPP on a Mac OSX Mavericks. I also upgraded to the latest wordpress version (3.8.1). I already tried the ff methods to solve this:
Method 1: I added the ff codes to the wp-config.php
define('UPLOADS', '/migsmarbella.com/wp-content/uploads');
define('WP_CONTENT_URL', 'http://migsmarbella.com/wp-content');
"migsmarbella.com" is the name of my wordpress folder.
Method 2: CHMOD the particular folder "migsmarbella.com" using Terminal Utility
sudo chown -R nobody:staff /applications/xampp/xamppfiles/htdocs/migsmarbella.com
Method 3: I also checked the "migsmarbella.com/wp-content" folder's permission settings (Right Click then "Get Info") which stated that "user" can read and write files, while "staff" and "everyone" can only read files.
Method 4: I unchecked the "Organize my uploads into month- and year-based folders" checkbox, then saved the setting changes inside Settings > Media.
Are there any better methods out there? Please help. Thanks.
P.S. Method 2 didn't work especially since it restricted my permission settings I have to undo the command I did by changing "nobody" into my mac's username.
Additional:
It seems this whole changing permission settings is getting more and more confusing. Can you guys give me the first step, the exact way to change permission settings of a folder in MAC? I tried to use Filezilla but I cannot find the command to chmod folders, at least in the Mac version.
First I'm using XAMPP for OS X 1.8.2-5 running the apache, mysql and ftp services, also the new wordpress 4.0, so I added this to my wp-config.php:
define('FTP_HOST', 'localhost');
define('FTP_USER', 'daemon'); /* check the user at XAMPP_dir/xamppfiles/etc/proftpd.conf */
define('FTP_PASS', 'xampp'); /* also the password is at XAMPP_dir/xamppfiles/etc/proftpd.conf */
define('FS_METHOD', 'ftpsockets');
define('FTP_BASE', '/XAMPP_dir/xamppfiles/htdocs/wordpress'); /* check/mod your path */
Also the ownership, hope this helps
After trying everything, I fount out this way to solve it which consisted in getting the actual username of the server. I wrote a small php script for this:
<?php
echo '<pre>';
$user = system('whoami', $retval);
echo '
</pre>
<hr />Ultima linea de la salida: ' . $user . '
<hr />Valor de retorno: ' . $retval;
?>
I ran it at http://localhost/wordpress/test.php and got the username daemon. I then changed the permissions to this user sudo chwon daemon -R wordpress and solved!
From your code you no need to define the path of your website as like migsmarbella.com Not sure why you targetting the path as with your site url? It take automatically of your corresponding site path you don't even put a path including your site url.
Your code of defining the path is not the correct way
define('UPLOADS', '/migsmarbella.com/wp-content/uploads');
define('WP_CONTENT_URL', 'http://migsmarbella.com/wp-content');
Correct way is as below.
Open up your wp-config.php file, located at the root of your WordPress installation, and add the following code
define('UPLOADS', 'wp-content/yourfoldername');
The codex specifies that it should be added before the line that says require_once(ABSPATH.’wp-settings.php’);.
If the directory that you are defining does not yet exist, WordPress will automatically create it as long as wp-content is writeable. Otherwise you can just go in and create the directory yourself via FTP. Make sure to make the new directory writeable.
Change upload organization
You can also change the way WordPress uploads are organized. Navigate to Settings > Media in the dashboard and you’ll find the option to check or uncheck the box next to “Organize my uploads into month- and year-based folders”.
The path you gave when doing chown is invalid. Paths are case sensitive.
Please also be aware there is a difference between chmod and chown.
Path should have been /Applications/XAMPP/xamppfiles/htdocs/migsmarbella.com
Run the following commands in terminal:
mkdir /Applications/XAMPP/xamppfiles/htdocs/migsmarblla.com/wp-content/uploads
sudo chown -R nobody:staff /Applications/XAMPP/xamppfiles/htdocs/migsmarblla.com/wp-content/uploads
The first creates an uploads folder since one doesn't already exist.
The second changes its ownership so folders can be created and files added by WP. Changing the ownership of the entire install will cause issues when you modify files. This only applies the change to the uploads dir.
In the recent version on xampp-7.2.6 in mac osx, the lampp process is running as daemon user.
And your wordpress folder might not have permissions to create the plugin folder in the directory. In order to resolve this issue, I changed the permissions of the webiste folder.
chmow daemon -R website
It worked.

Timthumb can't show image after it's uploaded

I'm using Wordpress plugin called User Avatar, that uses Timthumb for image display. When I open page to show the image, it gives error 500 in the console, and when I use that image link in new tab, I get following error:
A TimThumb error has occured
The following error(s) occured:
Could not create the index.html file - to fix this create an empty file named index.html file in the cache directory.
Could not create cache clean timestamp file.
Query String : src=http://my.domain.com/wp-content/uploads/avatars/1/1358504649-bpfull.jpg&w=150&id=1&random=1358504649
TimThumb version : 2.8.10
I persume it's a server error or misconfiguration, everything is being uploaded into folder uploads, then into avatars subfolder, which has 0777 permission, folder 1 also has 0777.
Insinde, there are both cache and temp folders, both with 0777 permissions.
GD Image Lib is enabled on the server.
Look in your timthumb-config.php, to check if the FILE_CACHE_DIRECTORY is set to the directory you think it is.
You could also delete the existing index.html file that's in the tim thumb cache directory, as tim thumb will automatically create it (back it up somewhere first just in case)
You may also need to check the config file to see if the MEMORY_LIMIT is set high enough for your particular images.
You should also check that the cache folder is owned by the webserver and not by you.
Other troubleshooting help here: http://www.binarymoon.co.uk/2010/11/timthumb-hints-tips/
Just like #jopacic said. What also worked for me was the following:
Changing the "cache" directory permission to 777
Deleting index.html file in the "cache" directory
Try that, it should work

Blank Page Encountered When Moved Wp-content Directory Outside

I'm trying to install Wordpress with clean subversion repositories, as in http://codex.wordpress.org/Installing_WordPress_With_Clean_Subversion_Repositories. I have followed every step accordingly until the second last step, where it says 'You should now be able to view the site via the root URL (http://example.com)', and indeed I can see my website on, say, http://example.com.
Once I go to the final step of changing the wp-config.php though, http://example.com draws a blank page. I am quite sure the wp-config.php is the problem, i.e. Wordpress doesn't know that it should retrieve my wp-content contents from outside the core Wordpress directory. My directory structure is as such:
.htaccess
core/
custom/
wp-config.php
, where core/ holds the files checked out with Subversion, custom/ holds my themes/ and plugins/ directory, and wp-config.php contains the below lines:
define('WP_CONTENT_DIR', dirname(__FILE__) . '/custom');
define('WP_CONTENT_URL', 'http://example.com/custom');
I have tried other variations, like:
define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/custom');
define('WP_CONTENT_URL', 'http://example.com/custom');
I have also tried hardcoding the local path, like:
define('WP_CONTENT_DIR', '/home/MYUSERNAME/example.com/custom');
define('WP_CONTENT_URL', 'http://example.com/custom');
, but none of the above works. Then I renamed the custom/ folder to wp-content/, but again nothing. I even went into Dreamhost to prevent redirecting http://example.com to http://www.example.com and vice versa, but again to no avail. I don't believe core/ is the problem, because I can access the Dashboard via http://example.com/core/wp-login.php, and the Dashboard says it can't detect my themes, which confirms my suspicion that WP doesn't know to retrieve the files from the custom/ folder.
By now, I have run out of ideas as to where could the problem be. Can anyone experienced in this area please give me some advice? Thanks a million.
Ensure that your statements come BEFORE the call for wp-settings.php, which is usually around line 90. Wp-settings (or more accurately default-constants.php) checks if the paths and URLs have already been defined, so you want to make sure you define them beforehand.
If that isn't the issue then check if $_SERVER['DOCUMENT_ROOT'] is returning the values you expect; you might have issues if working in a sub-directory.

Resources