Error Uploading images in drupal - php

I was trying to upload a custom logo to my drupal site which runs on IIS 8 with PHP.
I got the following upload error :
" Warning: move_uploaded_file(temporary://logo.png): failed to open stream: "DrupalTemporaryStreamWrapper::stream_open" call failed in drupal_move_uploaded_file() (line 1642 of C:\inetpub\wwwroot\drupalfull\includes\file.inc).
Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\php25C3.tmp' to 'temporary://logo.png' in drupal_move_uploaded_file() (line 1642 of C:\inetpub\wwwroot\drupalfull\includes\file.inc).
File upload error. Could not move uploaded file."
Please help me. I have set both read and write permissions on IIS but still it does not work.

Create sites/default/files/tmp folder and give full permissions (777) and change 'Temporary directory' at admin/config/media/file-system.
I think it fixes yout problem.
Regards.

If you are running ISS8 (web server) then the file path is different then the default for Unix.
Make sure you have the temporary folder setup correctly on your settings in Drupal and the folder has write permissions.
You can follow this article at step 5 and 6.
Create the folder:
Drupal uses the Sites\Default\Files directory to store temporary files and therefore must be able to write and modify files in this folder.
Create the folder:
C:\inetpub\wwwroot\Drupal>md sites\default\files
http://www.iis.net/learn/application-frameworks/install-and-configure-php-applications-on-iis/install-drupal-on-iis

Your problem is most likely the permission problem inside drupal. Since you are using windows system, you need to make sure the folder sites/default/files have writable permission for the IIS server. Config the permission to be writable for all user and see if it is working and then limit the permission step by step until you feel comfortable.

I'm going to put another answer in here because I guarantee I'm going to forget how I fixed it!
Basically, on Windows, the default upload folder for PHP is C:\Windows\Temp. As part of the Drupal upload, it moves files from the PHP upload folder to the Drupal Temporary//: folder. There is an issue however in PHP whereby the PHP executable needs read permission to the full path to the uploaded files, so C:\Windows\Temp. If this is not given, it will error out and the file will not be moved.
Details are at http://php.net/manual/en/function.realpath.php which is a function call made deep in Drupal's upload file code.
My fix was to create a folder elsewhere, say C:\PHPTemp, and modify PHP's settings (session.save_path and upload_tmp_dir) to point to this folder instead. After giving IIS_IUSRS full control (overkill? probably!), I was then able to upload images!

Related

PHP - Issue with move_uploaded_file

I've used move_uploaded_file successfully in the past, however I'm having an issue with permissions I believe with a new server I'm testing this on. I've created a folder named "uploads" for the uploads to be moved to via FTP. Here's a screenshot showing the permissions:
Everyone has read/write access, but when I upload a file I'm getting an error on the line that moves the file to the "uploads" directory:
if (move_uploaded_file($_FILES['photo1']['tmp_name'], $upload_directory.$uploadedFile)) {
The file is not moved to the "uploads" folder and looking at the server log I can see entries like this:
php[1344]
PHP Warning: move_uploaded_file(uploads/2.jpg): failed to open stream: Permission denied in C:\Program Files\FileMaker\FileMaker Server\HTTPServer\conf\test_upload\index.php on line 206
PHP Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\php2D93.tmp' to 'uploads/2.jpg' in C:\Program Files\FileMaker\FileMaker Server\HTTPServer\conf\ test_upload\index.php on line 206
I can't see how it can be a permissions issue if all users have read/write/execute on the "uploads" folder? Here are the variables:
$upload_directory='uploads/';
$uploadedFile= $_FILES['photo1']['name'];
It appears that uploads/2.jpg is $_FILES['photo1']['tmp_name'] and should therefore have been uploaded to the server's /tmp/ directory. On most systems, because /tmp is a system dir, it has restricted permissions on it.
See if you can alter the perms on /tmp or find out exactly which dir the tmp uploaded file is being moved to first, before being "uploaded" (and then alter the perms on that dir).
Regardless, the path to the file as passed to move_uploaded_file() doesn't look right. It needs to be a full-path. Possibly the server-error you're seeing is not happening at precisely the same time as the upload operation takes place.
I wasn't able to fix this via FTP settings. I had to adjust the settings by logging in to the Windows Server and changing the security settings on the folder I was trying to move files into so that the "Users" had read/write access.

cannot includ a existing file - failed to open stream: Permission denied

this is not a duplicate question, I read all related questions, and didn't find my answer.
I want to include a file that exists :
/var/www/html/monitor/protected/extensions/curl/curl.php
and my code is :
include('/monitor/protected/extensions/curl/curl.php');
and I'm getting this error :
include(/var/www/html/monitor/protected/extensions/curl/curl.php): failed to open stream: Permission denied
and the file has 777 permission.
My question is :
is it possible that a file exists and have a 777 permission and a proper chown AND still give this error?
Update : I had used all three possible ways :
include('/monitor/protected/extensions/curl/curl.php');
include('monitor/protected/extensions/curl/curl.php');
include('/var/www/html/monitor/protected/extensions/curl/curl.php');
Im using php 5.3
Note: when including another file in the same directory, it includes without any problem
I know this is late, but I just want to confirm Alireza Fallah's answer. This also worked for me. It looks like it has to be the original owner. So unzip/unrar the php files on the same machine you want to use it on. Hope this helps!
You're using the wrong path. If the file exists at
/var/www/html/monitor/protected/extensions/curl/curl.php
Then you should include that exact string.
include('/var/www/html/monitor/protected/extensions/curl/curl.php');
/ means the root of the file system. You get permission denied because you most certainly don't have permission to / and /monitor doesn't exist
Alternatively you can include it relatively. By dropping the first / you would do:
include('monitor/protected/extensions/curl/curl.php');
This will work if the running script is also in /var/www/html.
I think you're getting confused at the difference between the HTTP path and the system path. PHP files are included from the system path and should be referenced by the system path.
I deleted the file, and created again, and my problem solved.
the original file was downloaded from the internet and unzipped from a zipped file.
I think there was a problem with creating the file by original author.
This is very odd! but it worked

Wordpress Error: A TimThumb error has occured

I've encountered an error after installing wordpress onto a new domain.
I've contacted the theme developer and have had no luck resolving the issue.
I receive the following error when i copy the image link:
Warning: touch() [function.touch]: Utime failed: Permission denied in /home/domain/public_html/wp-content/themes/folioway/core/thumb.php on line 190
Warning: Cannot modify header information - headers already sent by (output started at /home/domain/public_html/wp-content/themes/folioway/core/thumb.php:190) in /home/domain/public_html/wp-content/themes/folioway/core/thumb.php on line 413
A TimThumb error has occured
The following error(s) occured:
Could note create the index.html file.
Query String : src=/wp-content/uploads/2012/03/CoffeetabeBox-custom_web1.jpg&w=187&h=187&zc=1&q=90
TimThumb version : 2.8.2
I have not modified anything else aside from some CSS.
The thumbnails do not appear on the pages, however, the images do appear in lightbox.
I have set the permissions to the cache folder to 777, but this has not resolved the issue.
Any help would be greatly appreciates. Thanks.
It happened to me too, and this is the second time!
If you don't have time to discover why, but you want to keep it working, just rename, or delete your /cache folder; then, create a brand new /cache folder, set permissions to 777, and it will work again.
I found that the cache folder this is referring to is the one within the same folder as timthumb.php - find that file and the related cache folder and give the cache folder 777 permissions.
if you are on a linux based server,
first find the FILE_CACHE_DIRECTORY from the config file by (ex. in linux server open the file in vi commond)
vi /system/web/esupu/wp-content/themes/gadgetry-parent/framework/timthumb/timthumb-config.php
it could be like
define('FILE_CACHE_DIRECTORY', '../../cache/');
SO we change the cache folder ownership to user "www-data" which is the default user for Apache web server which runs this php codes,
sudo chown -hR www-data:www-data /system/web/esupu/wp-content/themes/gadgetry-parent/cache/
also, now better check if folder can be writable too (chmod permissions to 777)
Instead of using 777 as others have suggested, use 755 to the /cache folder.
I just delete the cache folder and refresh the page where code was, it started working.
I think it is the problem of file permission.
Headers already sent is usually a symptom of whitespace either at the beginning or the end of the file - check timthumb.php and make sure you have no blank lines or space either before the
The other possibility is that /wp-content/uploads/ is not writable by the web server, but I'd bank on the first one being the cause.
I added this to a php.ini file:
display_errors = Off
display_warnings = Off
output_buffering = On
TimThumb is a separate open source project that is used by many WP plugins.
If updating folder permissions doesn't work for you, another solution which worked for me was to update the plugin's TimThumb script with the most recent version. You can download it here:
https://timthumb.googlecode.com/svn/trunk/timthumb.php
In my case this file was in wp-content/plugins/events-manager/includes/thumbnails
For others that have this issue when using the FiatLux Wordpress Theme, as I am here is the solution:
Open FTP like Filezilla
Navigate to yoursite/wp-content/themes/fiatlux/includes*
Delete the cache folder
Recreate the cache folder, with permission setting 755
Download the updated timthumb.php file from GitHub and replace (I renamed the old one timthumb.old to test
If you use a Media server/ CDN, then be sure to add that site to the $ALLOWEDSITES array in TimThumb.php file
*If using another Wordpress theme, then find the TimThumb.php file and corresponding cache folder in that theme/ plugins folder in wp-content
in
src=/wp-content/uploads/2012/03/CoffeetabeBox-custom_web1.jpg&w=187&h=187&zc=1&q=90
try put a '?' between .jpg and &w, so it will be like this
src=/wp-content/uploads/2012/03/CoffeetabeBox-custom_web1.jpg?&w=187&h=187&zc=1&q=90

need help understanding file permissions setting for the PHP application

i have developed an application on Macintosh using MAMP
when i upload it to the server which is powered by Cpanel11, CentOS 5.. it gives several error regarding file permissions by default it gives 0700 file permission to most of the files which does not work within my server. i would want to know how do i apply the file permission settings for my PHP application,
the directory structure or the rule i want to apply is for the following conditions.
a)File uploading Directory
b) most of the php file is using include_once()
c) the normal php files which communicates with each other.
thank you
File uploads in PHP first hit the defined temporary directory (see 'upload_tmp_dir' directive in your PHP.ini) and finally your intended destination directory (PHP command "move_uploaded_file").
Your PHP process runs as a certain user that needs to own the destination directory or is in a group that is allowed to write to this directory - unless the whole directory is not writable for everyone (it's not in your case).
Try chmod after move_uploaded_file.

Can't Upload File on IIS

I am on a shared-hosting account with GoDaddy it's a windows Server and I am getting this error when attempting to upload a file:
Warning: move_uploaded_file(D:\Hosting\6903\html\pdfs\ALDOmypdfAP.pdf) [function.move-uploaded-file]: failed to open stream: Permission denied in D:\Hosting\6903\html\back.php on line 436
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\Temp\php\php98C.tmp' to 'D:\Hosting\6903\html\pdfs\ALDOmypdfAP.pdf
I have heard that I can set my php.ini file to change the directory that it's immediately being uploaded to, which would work, however I can't access my php.ini file.
I have tried to create my own php.ini file in the root of my directory, and it causes all sorts of problems, such as not finding the correct MySQL configuration files, goDaddy's support on this was to remove the custom php.ini file, ridiculous, I know.
I have tried to use ini_set like this
ini_set('upload_tmp_dir', 'D:/Hosting/6903/html/pdfs/');
But it hasn't made any effect. Do I have any other options here? Thank you!
UPDATE: From Coda the Octal permissions read 777 of the destination directory.
As far as I know, you need to give the IUSR_MACHINENAME account write permissions specifically on the folder that you are trying to write to, or else it will fail. I don't know what Coda is, but can it allow you to set permissions for specific users?
Had the similar problem.
Fixed it by giving all permissions to usergroup "Authenticated User".
It took me couple of hours to realize it. This post kind of gave me the hint.
I hope my share will help others.
Maybe this can help...
Find and open php.ini in PHP folder (In my case c:\Program files(86)\PHP)
Search for upload_tmp_dir word and do one of two posibilities
--Posibility 1
3.1 Set upload_tmp_dir = "[Some folder with full permission for IUSR user]"
--Posibility 2
3.2 Search in windows explorer for the folder that is setted in upload_tmp_dir (In my case C:\WINDOWS\Temp)
3.2.1 Right click on C:\WINDOWS\Temp -> Properties -> Security -> Edit button -> Add, then add IUSR user and set full permissions to this -> Accept button.
I think this can help someone.
The problem probably comes from the final destination directory more than the temporary directory.
Normally, if the file cannot be uploaded at all, $_FILES['yourfile']['error'] will be set to UPLOAD_ERR_CANT_WRITE (7). From the error message, it tells us the problem is that move_uploaded_file can't either read from the temporary directory (unlikely), or write to the destination directory (most likely).
Check and maybe try changing the permissions on the destination directory.

Categories