Is it for me or everyone that the thumbnails generated by CI have 777 permissions ?
how can I set it to have just 644 by default ??
Thanks
in your application/configs/constants.php file you have 4 constants:
define('FILE_READ_MODE', 0644);
define('FILE_WRITE_MODE', 0666);
define('DIR_READ_MODE', 0755);
define('DIR_WRITE_MODE', 0777);
For the Image_Lib library codeigniter stores the image file using DIR_WRITE_MODE for some unknown reason.
You should double check this with the CI Guys as i believe they should be using FILE_WRITE_MODE.
you can open the library file and manually modify the sections such as
if ($this->dynamic_output === FALSE)
{
if ($this->orig_width == $this->width AND $this->orig_height == $this->height)
{
if ($this->source_image != $this->new_image)
{
if (#copy($this->full_src_path, $this->full_dst_path))
{
#chmod($this->full_dst_path, DIR_WRITE_MODE);
}
}
return TRUE;
}
}
and change the line #chmod($this->full_dst_path, DIR_WRITE_MODE); to FILE_WRITE_MODE so that it writes correctly.
there is a few sections of the file like this so you may have to search for others
Related
I have the following code :
if (!file_exists('/public_html/'.'classic/'.'test'.'/')) {
if(!mkdir('/public_html/'.'classic/'.'test'.'/', 0777, true)) {
return false;
}
}
This create only the folder /classic witch have the permission 0755 and another owner. How to change to create recusively 2 folders : /classic/test/ ? Thx in advance and sorry for my english
I found a solution by using umask :
$oldumask = umask(0);
mkdir('mydir', 0777); // or even 01777 so you get the sticky bit set
umask($oldumask);
I am trying to install a Magento package, but I get No file was uploaded
Its coming from this code because $_FILES is an empty array in /downloader/Maged/Controller.php
/**
* Install uploaded package
*/
public function connectInstallPackageUploadAction()
{
if (!$_FILES) {
echo "No file was uploaded";
return;
}
if(empty($_FILES['file'])) {
echo "No file was uploaded";
return;
}
$info =& $_FILES['file'];
if(0 !== intval($info['error'])) {
echo "File upload problem";
return;
}
$target = $this->_mageDir . DS . "var/" . uniqid() . $info['name'];
$res = move_uploaded_file($info['tmp_name'], $target);
if(false === $res) {
echo "Error moving uploaded file";
return;
}
$this->model('connect', true)->installUploadedPackage($target);
#unlink($target);
}
It might be worth noting that product uploads work fine.
The only log output I get is
2014-07-03T18:44:15+00:00 ERR (3): Warning: array_key_exists() expects parameter 2 to be array, null given in /var/www/vhosts/example.com/httpdocs/app/code/core/Mage/Captcha/Model/Observer.php on line 166
exception.log was empty
Make sure that your var folder in magento installation is fully writable. 777 permission. All folders and files.
You can try uploading a small dummy file first to check if the error stays the same.
There is a file upload limit which might be reached.
File upload often fails due to upload_max_filesize or post_max_size being too small as mentioned in Common Pitfalls section of the PHP documentation.
Use firebug in firefox to check if your form does has enctype="multipart/form-data".
Check the user group it was created with,
To explain, recently I had some file saving issues. Turned out I had created the folder using the Root user for the server, and the CPanel user ( the one php was running under ) didn't have permission to write in folders owned by the Root account, even when setting the permissions to 777.
Just a thought.
First check if your installation is configured properly
see#http://php.net/manual/en/features.file-upload.common-pitfalls.php
Also, if you upload with PUT/xhr the file is on the input stream
$in = fopen('php://input','r');
see#http://php.net/manual/en/features.file-upload.put-method.php and https://stackoverflow.com/a/11771857/2645347,
this would explain the empty $FILES array, in case all else is ok and the upload works via xhr/PUT.
$_FILES is an associative array of items uploaded to the current script via the HTTP POST method. All uploaded files are stored in $HTTP_POST_FILES contains the same initial information, but is not a superglobal. So, ... be sure that method is POST
Always check that your form contains correct enctype:
<form ... enctype="multipart/form-data"> ... </form>
Sometimes happens that when someone upload multiples file, $_FILES return empty. This could happen when I select files that exceed some size. The problem can be in the POST_MAX_SIZE configuration.
On
app/code/core/mage/captcha/model/observer.php
change
public function checkUserLoginBackend($observer)
{
$formId = 'backend_login';
$captchaModel = Mage::helper('captcha')->getCaptcha($formId);
$loginParams = Mage::app()->getRequest()->getPost('login');
$login = array_key_exists('username', $loginParams) ? $loginParams['username'] : null;
if ($captchaModel->isRequired($login)) {
if (!$captchaModel->isCorrect($this->_getCaptchaString(Mage::app()->getRequest(), $formId))) {
$captchaModel->logAttempt($login);
Mage::throwException(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
}
}
$captchaModel->logAttempt($login);
return $this;
}
to
public function checkUserLoginBackend($observer)
{
$formId = 'backend_login';
$captchaModel = Mage::helper('captcha')->getCaptcha($formId);
$login = Mage::app()->getRequest()->getPost('username');
if ($captchaModel->isRequired($login)) {
if (!$captchaModel->isCorrect($this->_getCaptchaString(Mage::app()->getRequest(), $formId))) {
$captchaModel->logAttempt($login);
Mage::throwException(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
}
}
$captchaModel->logAttempt($login);
return $this;
}
Your issue is:
"Captcha Observer throws an error if login in RSS feed" issue #208
or if you wish you could only replace the variable $login to be like this:
$login = array_key_exists('username', array($loginParams)) ? $loginParams['username'] : null;
You may try out below points.
Use Magento Varien File Uploaded Classes to Upload the files.
Magento File Uploader
1) Check enctype="multipart/form-data" in your form.
2) Use Magento Form Key in your form.
3) Use Varien file uploader to upload your files using below links answers.
i wanna try this
link : How to check using PHP FTP functionality if folder exists on server or not?
tell me if my code is right;
i cant seem to find the folder and it echoes the failed
sample ftp account is
user: admin#mywebsite.com
pass: name#pasword
ftp file root is : /home/mywebsite/public_html/admin
path folder i want to find is: public_html/admin/userfiles
i set the path ftp account path on the admin from cpanel
if(is_dir('ftp://admin#mywebsite.com:name#pasw0rd#mywebsite.com/userfiles'))
{
echo 'found';
}
else
{
echo 'failed';
}
There are some prerequisites to using 'ftp://` this way:
The PHP directive allow_url_fopen must be set to true;
The target server must support passive ftp
Assuming both of those things, your URL must be accurate. The convention is ftp://name:password#server.example.com/folder. Your URL appears to have a spurious :name# in it.
ftp://admin#mywebsite.com:name#pasw0rd#mywebsite.com/userfiles'
^^^^^^
FTP function checks if a directory exists
<?php
function ftp_is_dir( $dir ) {
global $ftpcon;
// get current directory
$original_directory = ftp_pwd( $ftpcon );
// test if you can change directory to $dir
// suppress errors in case $dir is not a file or not a directory
if ( #ftp_chdir( $ftpcon, $dir ) ) {
// If it is a directory, then change the directory back to the original directory
ftp_chdir( $ftpcon, $original_directory );
return true;
}
else {
return false;
}
}
?>
I need to read pdf extension file from some links which I crawled from a web. The links is saved in $link variable.
but sometimes, the extension doesn't written in the link, for example : http://tstc.bz/docs/490 besides 490 is a pdf file, the extension will exist when I click it. How to read that hidden extension ? thank you
I've tried using PATHINFO
if (strtolower(pathinfo($link,PATHINFO_EXTENSION)) === 'pdf'){
Use mime_content_type, documentation here, to fetch the type of the file you're trying to load.
If you are caching the content of the links, this is a good option, as you need to have the file locally. Otherwise, do like baba is suggesting, use get_headers with the link (documentation here), passing a non-zero value as the second parameter to have the keys in your result array. Then, it's simply a matter of reading [Content-Type] from your resulting array
You can use get_headers
$link = "http://tstc.bz/docs/490";
if (getPdf($link)) {
// yes its a PDF File
}
Function Used
function getPdf($link) {
$ext = strtolower(pathinfo($link, PATHINFO_EXTENSION));
if (empty($ext)) {
$type = array_change_key_case(get_headers($link, true), CASE_LOWER);
if (is_array($type['content-type']))
return false;
if (strtolower($type['content-type']) === "application/pdf") {
return true;
}
}
if ($ext === 'pdf') {
return true;
}
return false;
}
Currently I have the following:
$config['upload_path'] = 'this/path/location/';
What I would like to do is create the following controller but I am not sure how to attack it!!
$data['folderName'] = $this->model->functionName()->tableName;
$config['upload_path'] = 'this/'.$folderName.'/';
How would I create the $folderName? dictionary on the sever?
Jamie:
Could I do the following?
if(!file_exists($folderName))
{
$folder = mkdir('/location/'$folderName);
return $folder;
}
else
{
$config['upload_path'] = $folder;
}
am not sure what they are talking about by using the file_exist function since you need to check if its the directory ..
$folderName = $this->model->functionName()->tableName;
$config['upload_path'] = "this/$folderName/";
if(!is_dir($folderName))
{
mkdir($folderName,0777);
}
please note that :
i have added the permission to the folder so that you can upload files to it.
i have removed the else since its not useful here ( as #mischa noted )..
This is not correct:
if(!file_exists($folderName))
{
mkdir($folderName);
}
else
{
// Carry on with upload
}
Nothing will be uploaded if the folder does not exist! You have to get rid of the else clause.
$path = "this/$folderName/";
if(!file_exists($path))
{
mkdir($path);
}
// Carry on with upload
$config['upload_path'] = $path;
Not quite sure what you mean by 'dictionary', but if you're asking about how to create a variable:
$folderName = $this->model->functionName()->tableName;
$config['upload_path'] = "this/$folderName/";
To add/check the existence of a directory:
if(!file_exists($folderName))
{
mkdir($folderName);
}
else
{
// Carry on with upload
}
Not 100% sure what you want from your description so here are a few suggestions:
If you need to programmatically create a folder using PHP you can use the mkdir() function, see: http://php.net/manual/en/function.mkdir.php
Also, check out the Codeignitor file helper for reading and writing files:
http://codeigniter.com/user_guide/helpers/file_helper.html
If the folder already exists, you need to make sure the permissions are write-able. On windows you can right click on the folder, properties, security and edit there. On Linux you'll want the chmod command.