Drupal 7 - can't upload files - file

I'm getting an error when trying to upload any type of file via Content>Files>Add File. The error reads "The file filename could not be saved. An unknown error has occurred. The file in the Upload a new file field was unable to be uploaded."
I've read through many threads and most seem to indicate a permissions problem. I've checked that all directories are configured properly. Public files are set as sites/default/files; private files are set as sites/default/files/private; and temporary is set as sites/default/files/tmp.
Then I found this error in the server logs:
[Tue Mar 27 10:49:26.932464 2018] [proxy_fcgi:error] [pid 20750:tid 140070898026240] [client nn.nnn.nn.nn:63784] AH01071: Got error 'PHP message: PHP Warning: File upload error - unable to create a temporary file in Unknown on line 0\n', referer: http://ipaddress.com/file/add
Any ideas what might be wrong here?
Thanks,
CJ

This is definitely a permissions issue.
You mention the path of the different folders (public, private, and tmp), but that is a completely different thing.
What you need to check is that user running the webserver has permissions to write on those aforementioned folders.
Now, you don't mention what server are you using, so I'll assume you're running Apache, and the Apache user and group is called apache in CentOS and www-data in Ubuntu.
You should navigate to those folders (actually to the folder where this folders are placed) and type a ls -la sentence in the terminal, to get a list of permissions for them, as well as the name of the user that owns the folders.
The Apache user needs to access and write in those folders.

I have come across the similar problem once. Solution to this problem is to give the 'write' permission to 'others' as well on tmp directory. You might wonder that this is /tmp directory I am talking about, as while uploading a file it must pass through /tmp directory to the desired location.
So give the write (other) permission to /tmp and sites/default/files/tmp directory. Hope this will help.

Related

Unable to upload file from $_FILES array in drupal7

I am trying to upload file from $_FILES array. but getting following error in drupal7.
The specified file temporary://fileOYnPHK could not be copied, because the destination directory is not properly configured.
This may be caused by a problem with file or directory permissions. More information is available in the system log.
The sites/default/files has permissions 777
Here is my code
if($_FILES['files']['name']['field_tenant_review_ref_und_form_field_tenancy_document_und_0']){
$file_path = file_save_data(file_get_contents($_FILES['files']['tmp_name']['field_tenant_review_ref_und_form_field_tenancy_document_und_0']),
'public://sites/default/files/'.$_FILES['files']['name']['field_tenant_review_ref_und_form_field_tenancy_document_und_0']);
}
//$tenant_review->field_tenancy_document->file->set($file_path);
Is there any mistake in code? Please suggest.
'public://sites/default/files/'
should probably be changed to
'public://'
because it probaby already contains the sites/default/files path, if that path is set in Drupal settings as the public files path.
Edit:
The permissions for the files folder shoud be set as most permissive to 775 for security reasons.

WinSCP log not generating

I am using WinSCP for file transfer to a remote instance.
C:\Program Files (x86)\WinSCP>WinSCP.com sftp://root#<some IP>/ /log="C:
\winscp.log"
put D:\backup\hello.txt ./test1/
It is logging in perfectly and also the file is transferring, but it is not generating any log for that on the local path I have specified. How to resolve the problem?
If there's any problem with logging, WinSCP would issue an error message on its output. It would help if you show us the output.
Anyway, I guess the problem is that one generally does not have a write access to C:\ root folder. Of course, unless you run WinSCP as an administrator.

save pdf on server fpdf

I am generating a pdf with fpdf in cakephp and I try to save it on the server.
I do it like this :
$fpdf->Output("D:/Files/mypdf.pdf",'F');
but it doesn't save.
I think it doesn't find the folder, but I don't know how specified it?
I have put the all the right on the folder.
I don't know if it is a cakephp restriction or just my directory?
Try this
$fpdf->Output(WWW_ROOT."files\mypdf.pdf", 'F');
As this code works fine locally, it's probably server-problem.
(1) Are you sure you can create files? Most free servers disallow creating files.
(2) Have you tried it with different location e.g. the current root location $fpdf->Output("mypdf.pdf",'F')
Anyway, you should enable error reporting in your index.php. If it was matter of directory not found you would get this result:
Warning (2): fopen(D:/Files/mypdf.pdf): failed to open stream: No such file or directory [ROOT\vendor\fpdf\fpdf.php, line 1025]
FPDF error: Unable to create output file: D:/Files/mypdf.pdf
Just a wild guess but change the slashes to windows style.
$fpdf->Output("D:\Files\mypdf.pdf",'F');
or even
$fpdf->Output("D:\\Files\\mypdf.pdf",'F');

How to deploy CakePHP-application on CentOS?

I almost managed to deploy a CakePHP-application on CentOS-server, but it still needs little configuration. I have enabled mod_rewrite in /etc/httpd/conf/httpd.conf and restarted apache-server.
Then I have put Cake core library in /home/user/cakephp-core/
I get message "500 internal error" when i try to go to this page through web-browser.
In apache-logs I found following messages:
PHP Warning: include(/$HOME/cakephp-core/lib/Cake/bootstrap.php): failed to open stream: Permission denied in /srv/www/site/public_html/main/index.php on line 96
PHP Warning: include(): Failed opening '/$HOME/cakephp-core/lib/Cake/bootstrap.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /srv/www/site/public_html/main/index.php on line 96
PHP Fatal error: CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your /cake core directory and your /vendors root directory. in /srv/www/site/public_html/main/index.php on line 101
it says something about "permission denied"... to whom I should give permissions and where? I gave "apache:apache" to tmp/-folder... Any ideas?
Simply read the log and try to understand it.
It pretty clearly tells you what has insufficient permissions. The linux command to set permissions is chmod. You also want to make sure, as the text already tells you, that your CakePHP core include path is correct. Double check that too.

CakePHP Shell issue

I am just getting started with Cakephp shell and running into issues.
My cake core library is under path d:/libs/cake
My app is setup under d:/servers/htdocs/myapp
I wrote a test shell under d:/servers/htdocs/myapp/vendor/shells
class ReportShell extends Shell {
var $uses = array('Appt');
function main() {
echo $this->Appt->find('first');
}
}
When I try to run this code from d:/servers/htdocs/myapp , It gives me an error
Warning: include_once(d:/servers/htdocs/myapp/config/database.php): failed to open stream: No such file or directory in d:/libs/cake\libs\mode
l\connection_manager.php on line 23
Warning: include_once(): Failed opening 'd:/servers/htdocs/myapp/config/database.php' for inclusion (include_path='.;D:\work\xampp\php\PEAR') in d:/libs/cake\libs\model\connection_manager.php on line 23
Fatal error: ConnectionManager::getDataSource - Non-existent data source default in d:/libs/cake\libs\model\connection_manager.php on line 102
Reason is that it is trying to find database.php under 'd:/servers/htdocs/myapp/config/' and the correct path is 'd:/servers/htdocs/myapp/app/config/database.php'
What am I doing wrong here?
thanks
My app is setup under d:/servers/htdocs/myapp
No, the application directory (holding the config folder) is D:\servers\htdocs\myapp\app\.
Reason is that it is trying to find database.php under 'd:/servers/htdocs/myapp/config/' and the correct path is 'd:/servers/htdocs/myapp/app/config/database.php'
You are in the wrong directory, therefore it can't find your database config.
I wrote a test shell under d:/servers/htdocs/myapp/vendor/shells
Move your shell out of the global vendors folder at D:\servers\htdocs\myapp\vendors\shells to the application's vendors folder at D:\servers\htdocs\myapp\app\vendors\shells instead and try again.
(Note: I'm not actually sure where the global vendors folder should be when you have a setup where the cake and application directories are split from each other, but you definitely have to be in your application directory when running commands and not the myapp directory you're using.)
If you add D:\libs\cake\console\ to your PATH environment variable (remembering to close all cmd.exe processes afterwards) then you will simply be able to execute the following:
D:\servers\htdocs\myapp\app> cake report (from within the application directory)
Otherwise you will need to type the full relative or absolute path to the cake console executable and/or provide CakePHP with the absolute path to the application directory (if you are not in it):
D:\servers\htdocs\myapp\app> ..\..\..\..\libs\cake\console\cake report
D:\servers\htdocs\myapp\app> \libs\cake\console\cake report
D:\libs\cake\console> cake -app D:\servers\htdocs\myapp\app report
D:\> libs\cake\console\cake -app D:\servers\htdocs\myapp\app report
etc...
Hopefully you can see why just adding the correct folder to your PATH makes things a lot easier. :)
Try to run it from within the /app directory or with the -app parameter specified:
cake -app d:/servers/htdocs/myapp/app report
Thanks. Here was the issue
My shell script was under /myapp/vendor/shells which was wrong. It should have been under /myapp/app/vendor/shells. After I moved the file, it worked. Thank you
You should always be in your APP path to execute the cake console.
Your Shell File Should be in ..app/Console/Command/
If your file name is TestShell.php type command app> cake test

Resources