Codeigniter error log not working - codeigniter

I want to log my details for log my application event. So i have changed config.php as follows.
$config['log_threshold'] = 4;
$config['log_path'] = 'application/logs/main';
$config['log_date_format'] = 'Y-m-d H:i:s';
I use it in my controller as like this.
log_message('error', 'Some variable did not contain a value.');
I grant write permission to main file. bt it is not working. What is the issue.

log_path is meant to be a folder not a file. If main is a folder then you should add a trailing /

Related

October CMS issue with file attachment during tests

I am using October CMS
I have a model which has some attachOne and attachMany file attachments.
Both of these work fine during normal use.
However I am having difficulty with setting up tests
I have the following code in my test class
$logo = file(__DIR__ . '/assests/images/logo.png');
$file = new System\Models\File;
$file->data = __DIR__ . '/assests/images/Sample-Photo.jpeg';
$file->is_public = 1;
$file->save();
$nhd->developer_logo = (new System\Models\File)->fromData($logo, 'logo.png');
$nhd->development_photos->add($file);
$nhd->save();
$developer_logo_path = $nhd->developer_logo->getPath();
$photo_path = $nhd->development_photos[0]->getPath();
Both the ‘$developer_logo_path’ and ‘$photo_path’ variables successfully return a stored file path ( which actually points to a file which has been saved ) which is what i would except.
However if i then let the test run and execute the normal code. If I put a breakpoint in the component php file at the point after the model referred to in the test code as $nhd has been loaded there is a ‘developer_logo’ attached ( the AttachOne file ) but there are no ‘development_photos’ ( the attachMany file ).
As a result the template also does not output anything when {{component.development_photos}} is used
I also tried using the inline method to add the attachMany file ( $nhd->development_photos = (new System\Models\File)->fromData($photo, ‘logo.png’); ) and this also did not work.
Can anyone help me?

How to check whether a file contains "." (dot) operator

I have a code which asks user to upload a file. The file may be audio or image or anything. I asks user to enter file name. If he Enter file name my code adds extension to it. It is working fine. But if user enters extension say audio.mp3 then it saves as audio.mp3.mp3. So I have to check if user entered name contains dot then it should not take extension.
I used pregmatch but it is not working.
My code
$splitOptions = explode(',',$request->input('mediaName'));
$fileExtension = pathinfo($file[$i]->getClientOriginalName(),PATHINFO_EXTENSION);
$checkExtension = explode('.',$request->input('mediaName'));
if(preg_match("/[.]/", $checkExtension)){
$mediaName = $splitOptions[$i];
}
else
{
$mediaName = $splitOptions[$i]."_$fileExtension";
}
Please use laravel helper
$value = str_contains('This is my name', 'my');
// true

How to create wiki-family on MediaWiki-Vagrant?

Are there any roles to manage or create multiple wikis? I have checked Manual:Wiki family and understand the normal way of creating multiple wiki in a MediaWiki.
I'd like to share what I got in addition to the manual.
Beside of multiple domains/subdomain you can get also multiple path for multiple wikis. Each will stand with different configuration setup by adding the action path at the end line on each of your setting files as shown:
# End of automatically generated settings.
# Add more configuration options below.
$wgArticlePath = "/map/$1";
$actions = array( 'edit', 'watch', 'unwatch', 'delete','revert', 'rollback',
'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history',
'purge', 'info' );
foreach ( $actions as $action ) {
$wgActionPaths[$action] = "$wgArticlePath/$action";
}
$wgActionPaths['view'] = "$wgArticlePath";
Change the map variable to your path on each of the setting files then place them under the folders named exactly follow to your path.
So you can modify the code in the LocalSettings.php similar as below:
<?php
// Include common settings to all wikis before this line (eg. database configuration)
$paths = explode('/' , $_SERVER['REQUEST_URI']);
if($paths[2] === NULL) {$path = 'map';} else {$path = $paths[1];}
switch ( $_SERVER['SERVER_NAME'] ) {
case 'wiki.tophyips.info':
require_once "settings/$path/tophyips.php";
break;
case 'wiki.hyipscript.info':
require_once "settings/$path/hyipscript.php";
break;
case 'wiki.hyipmonitors.info':
require_once "settings/$path/hyipmonitors.php";
break;
default:
header( 'HTTP/1.1 404 Not Found' );
echo 'This wiki is not available. Check configuration.';
exit( 0 );
}
Change the map variable on $path = 'map'; to one of your default path of your choice from all the paths you put on the setting files above.
You may check the result of the configuration above on my wiki family page.
The mediawiki::wiki module is used for creating wikis. Some roles that use it are commons and private (there are surely more). If you just want to create a wiki without any extra configuration, you can just write mediawiki::wiki{<wikiname>:} and put it in puppet/modules/role/manifests/my_role.pp (inside a role block - see other role files for the format) and then you can enable/disable via vagrant roles.

Saving Intervention Image In Owners Folder in Laravel 5

I can change my code to save the uploaded image in the public dir but not when I want to their uploaded image in a folder as their company's name. For example of what works:
/public/company_img/<filename>.jpg
If the user's company name is Foo, I want this when they save save their uploaded image:
/public/company_img/foo/<filename>.jpg
This is in my controller:
$image = Input::file('company_logo');
$filename = $image->getClientOriginalName();
$path = public_path('company_img/' . Auth::user()->company_name . '/' . $filename);
// I am saying to create the dir if it's not there.
File::exists($path) or File::makeDirectory($path); // this seems to be the issue
// saving the file
Image::make($image->getRealPath())->resize('280', '200')->save($path);
Just looking at that you can easily see what it's doing. My logs shows nothing and the browser goes blank after I hit the update button. Any ideas
File::exists($path) or File::makeDirectory($path);
This line does not make sense, as you check if a file exists and if not you want to attempt to create a folder ( in your $path variable you saved a path to a file not to a directory )
I would do something like that:
// directory name relative to public_path()
$dir = public_path("company_img/username"); // set your own directory name there
$filename = "test.jpg"; // get your own filename here
$path = $dir."/".$filename;
// check if $folder is a directory
if( ! \File::isDirectory($dir) ) {
// Params:
// $dir = name of new directory
//
// 493 = $mode of mkdir() function that is used file File::makeDirectory (493 is used by default in \File::makeDirectory
//
// true -> this says, that folders are created recursively here! Example:
// you want to create a directory in company_img/username and the folder company_img does not
// exist. This function will fail without setting the 3rd param to true
// http://php.net/mkdir is used by this function
\File::makeDirectory($dir, 493, true);
}
// now save your image to your $path
But i really can't say your behaviour has something to do with that... Without error messages, we can only guess.

Check an image if existing already in the folder before uploading - Codeginiter

Do you have any sample codes or functions to check if an image name is existing already in the folder before uploading?
I've tried using file_exists() but it doesn't work, here is my sample code:
$path = FCPATH . "images2/";
$filename=$_FILE['userfile'];
$full_path = $path .$filename;
if(file_exists($filename))
{
///display error message///
}
Here is the simplest way to check if a file exist:
if(is_file($filename){
return true; //the file exist
}else{
return false; //the file does not exist
}
I'm assuming you are not getting the correct result with file_exists() because you don't include the full path (even tho you define it).
Try using the following: file_exists($full_path)
Also consider using some CI helper functions for handling files like images, or uploads. They are there to make this 'easier'.
File helper:
http://ellislab.com/codeigniter/user-guide/helpers/file_helper.html

Resources