Unable to upload file from $_FILES array in drupal7 - file

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.

Related

Drupal 7 - can't upload files

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.

Setting up ArangoDB cluster wihout DCOS

I'm working on setting up an ArangoDB cluster in an Ubuntu machine based on these instructions :
https://docs.arangodb.com/3.0/Manual/Deployment/Distributed.html
I keep getting the below error when i execute the first command in the above documentation with sudo. I ensured that all the directories
pointing to in the /etc/arangod.conf file has the required permissions. Please can you let me know if i'm missing something here.
Below is the error i get :
2016-08-23T07:29:52Z [26629] FATAL unable to create database directory: Failed to create directory [agency1] Permission denied
The command passes the database directory on the command line (agency1) and arangodb doesn't seem to have rights to create agency1 in your current working directory.
Either provide a proper working directory on the command line or specify one in the config file.
You need to first change the directory to /var/lib/arangodb3 or whatever data directory you have set and then run the command.

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');

Code to be executed before every page on server

I have an apache2 server, it has a vast and growing folder structure.
There is a set of instructions I would like to be executed at the beginning of every page in that website.
How do I implement that without pasting those very lines at the beginning of every file in the website?
I don't want to have the code at the beginning of every file.
I have tried changing the auto_prepend_file in php.ini to:
auto_prepend_file = ~/website_preview/say_hello.php
'say_hello' is a hello-world php script, but the script does still not get executed at all.
Wrong php.ini file, correct location is /etc/php5/apache2/php.ini
If all of your pages are in PHP, then I think you were on the right path with setting up auto_prepend_file in php.ini.
Try this:
Check your include_path in php.ini and if needed append a new path to it for your instructions file.
Copy your instructions.php file to the location from the include path.
Edit your auto_prepend_file in php.ini to be just the filename from step 2.
I tested this out and was able to get it working that way but had trouble specifying the path directly in the auto_prepend_file setting.
Also, when I had the auto_prepend_file setting configured improperly I received the following php error:
PHP Fatal error: Unknown: Failed opening required ...
Hope that helps.

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