WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#20330 new defect (bug)

Differences between creating folders for plugins and uploaded media (problem with safe_mode)

Reported by: pavelevap Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.3.1
Component: Upload Keywords:
Focuses: Cc:

Description

After installing 3.2.1 (into subdirectory test) there is missing URL path in menu Media - Store uploads in this folder. But nevermind, I am not sure if this is a bug or expected?

I tried to update Akismet automatically, no problem (only FTP credentials required). I tried to install new plugin automatically, also no problem.

Directories are created, plugins installed. But when I try to upload some media files, there is following error:

"Testing-picture-50g.jpg" has failed to upload due to an error
The uploaded file could not be moved to /data/www/h/domain.cz/public_html/test/wp-content/uploads.

When I look at "uploads" directory - there is CHMOD 775, but I "Cannot change attributes of remote files!"
When I delete this folder and create it manually, then everything works. But it is not possible to organize media into month- and year-based folders, because they are not working when created automatically by WordPress.

And I suppose there is some kind of problem in the way how creating folders for uploading media works. Yes, hosting is limited with safe_mode, but why creating folders and installing plugins works without problem and creating folders for uploaded media does not work?

We had several reports from different users about problems with uploading media and this is the only clue I could find. Maybe there is something which was fixed for updating processes, but not for uploading media (especially for creating directories). Any idea?

Also automatic upgrade to WP 3.3.1 works well. But in 3.3.1 there is probably a bug, because picture is not uploaded, but there is no Error reported (as in 3.2.1). It looks like media file is uploaded, but only media post is created and file is not uploaded (there is no thumbnail (only icon of missing picture). I suppose, that users should be notified what is going on here?

Summary in the end:

1) In WP 3.3.1 there is no error for users after unsuccessfull media upload and there should be (regression from 3.2.1).

2) There are different ways to create folders for updating/installing plugins and creating folders for media uploads and the second way does not work when safe_mode is on.

Attachments (1)

Upload_error.jpg (22.5 KB) - added by pavelevap 2 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 duck_2 years ago

Sounds related to/duplicate of #19800, especially the missing error message.

comment:2 pavelevap2 years ago

Yes, you are right. I tried latest trunk and error message is visible (little strange, see attached screenshot) and media item is not created.

So the main problem of this ticket is only second point - different ways to create folders for updating/installing plugins and creating folders for media uploads and the second way does not work when safe_mode is on.

pavelevap2 years ago

comment:3 dd322 years ago

Safe_mode significantly reduces the things that PHP can do, while offering limited advantages.

When upgrades are occuring, it's run through FTP, As such, it has much higher permissions available to it than PHP normally does. The Uploader doesn't use this, as most users would dislike being prompted to enter FTP details on every image upload.

In your case, you'll need to create the uploads folder manually, and chmod it to 0777 most likely, after that, you should be able to enable the "store uploads in year/month folders" option, and continue on your way..

comment:4 pavelevap2 years ago

Yes, I also tried to create uploads folder manually and use CHMOD 0777, but uploading does not work for year/month folders. There is following error:

"Testing-picture-50g.jpg" has failed to upload due to an error
Unable to create directory /data/www/h/domain.cz/public_html/test/wp-content/uploads/2012/03. Is its parent directory writable by the server?

There is folder "2012" automatically created, but "03" folder is not created. Folder 2012 has CHMOD 0777, but is owned probably by another user, because it is not possible to edit it through FTP client - "Cannot change attributes of remote files!"

I understand that creating folders is easier through FTP, but this way would be very usefull for other users with safe_mode problems. Is it possible to use FTP method with the help of any hook? Then it would be easy to make a safe_mode support plugin. And FTP credentials can be stored in wp-config.php as FTP_PASS and other constants?

comment:5 dd322 years ago

There is folder "2012" automatically created, but "03" folder is not created. Folder 2012 has CHMOD 0777, but is owned probably by another user, because it is not possible to edit it through FTP client - "Cannot change attributes of remote files!"

this is the exact problem safe_mode ends up introducing.. If you use your webhosts control panel file editor, you should be able to alter it from there (rather than ftp)

Is it possible to use FTP method with the help of any hook?

Nothing that's integrated into the file uploader, it would be a lot of work, for little return.

More modern server setups no longer use safe_mode (as it's no longer included in latest php builds) and use suexec/suphp (resulting in no need for safe_mode and user ownership issues).

comment:6 pavelevap2 years ago

Hmmm, so when hosting company uses safe_mode, then WordPress is "not working" (Media are significant part)? I thought that it is only any bug related to uploading media files. But media can be uploaded only without "storing uploads in year/month folders" option (for hundreds media files it will be terrible mess) and only when you create "uploads" folder manually and set high permission?

There is not any notice in the manual?

http://codex.wordpress.org/FAQ_Installation#Will_WordPress_run_in_PHP_Safe_Mode.3F

comment:7 pavelevap2 years ago

Nothing that's integrated into the file uploader, it would be a lot of work, for little return.

After going through many support questions, this would not be a little return. PHP 5.2.x and safe_mode will be there for many years.

http://wordpress.stackexchange.com/questions/19563/file-upload-with-server-in-safe-mode

http://stackoverflow.com/questions/2971369/cannot-upload-media-via-wordpress-uploader

http://wordpress.org/support/topic/dealing-with-php-with-safe-mode-on-cant-upload-images

It is a real problem for many users and there are many similar questions and no answer...

comment:8 pavelevap2 years ago

I tried to bypass this problem and found a partial solution.

WordPress wants to create directory "uploads/2012/04", but only "uploads" is created with another group and owner. I wrote a small plugin which uses Filesystem API and tries to hook to upload_dir filter to create folders with using "ftpext" method.

But, there are 2 problems:

1) In order to preserve current "uploads" folder, I should have change group and owner of "uploads" folder. But using ftpext there are chown() and chgrp() functions which everytime return false. I am not sure if it is possible to change group and owner of "uploads" folder by using ftpext method?

2) When I tried to hook to upload_dir, I can created special folder "wp-content/smuploads", but also original "wp-content/uploads" is automatically created. Is it possible not to create it?

Any ideas?

Still there is main problem - WordPress is useless when using safe_mode and uploading media. Maybe there should be any error message to emphasize this problem on uploading screen when safe_mode on?

Note: See TracTickets for help on using tickets.