Jump to content

[SOLVED]file responsible for Image creation??? Create 644 images


Recommended Posts

Hi,

I have problem with Presta or web hosting company. When I creating product, looks like everything going alright.
No errors or warnings!
But product image not appear in BO and in FO. After some research I found out what my new created images have 640 permissions. I tried contact my hosting company (networksolutions) and ask them to change default file permissions to 644, but they don't understand what I want from them. So I will not get from them any support.

Please, help me to figure out, how can I update script responsible for image creation, if in result I would like to get image with permission 644? It will be good what presta will generate images with chmod 644.

Please help me! I am searching for solution almost one month

Link to comment
Share on other sites

Thank you. I understand that, but my hosting provider doesn't. How I hate them!!!
I will try to check that function... Is it possible to modify code and specify permissions with Presta???

Nearly two weeks I am trying to solve that problem with my host helps and they just sending stupid email and nothing more.

You are my last hope!

Link to comment
Share on other sites

I did a Google search and found someone else with the same problem. If your host refuses to change your server configuration, it seems your only option is to change the permissions of your img and img/p directory to chmod 777, then change it back to chmod 755 after you've finished uploading images, since it is unsafe to use chmod 777 permissions.


Under some configurations imagecreatefromjpeg will create files that are owned by the webserver rather than the php user. For example, php may be run as phpuser and the image will be created under apache.

This can lead to permissions problems - only a +0777 will be enough to be able to create a picture.

My solution was to chmod over ftp to 0777 just before the picture is written then change back to 0755 when the image has been created.

The alternative of course would be to have a properly configured system...
Link to comment
Share on other sites

One more thing! I wrote little script in php which creates XML file on my server. Almost every time that new created XML file have 640 permission (like my pictures), so problem is really in server side... Probably even changed folder permissions to 777 will not help me in that situation

Link to comment
Share on other sites

Probably they understand that, but no result :) I am getting emails from them what they trying to reach my by phone... Or they doing what they can...
But more than 2 weeks still no result (but it is not community problem). Just if someone will suggest how to modify Presta in order to create 644 images, I will be very glad

Link to comment
Share on other sites

Try the following code:

$dirs = array();
$dirs[] = '/';

while (($dir = array_pop($dirs)) != NULL)
{
  if ($dir == '.' OR $dir == '..')
     continue;

  $files = scandir($currentDir . $dir);

  foreach ($files as $file)
  {
     if (is_dir($file))
     {
        chmod($file, 0755);
        $dirs[] = $file;
     }
     else
        chmod($file, 0644);
  }
}



I haven't tested it, but it should recurively set the permissions of all directories to 755 and files to 644 starting from '/'. Change that to the directory you want to start from.

Link to comment
Share on other sites

Try the following code:

$dirs = array();
$dirs[] = '/';

while (($dir = array_pop($dirs)) != NULL)
{
  $files = scandir(array_pop($dirs));

  foreach ($files as $file)
  {
     if (is_dir($file))
     {
        chmod($file, 0755);
        $dirs[] = $file;
     }
     else
        chmod($file, 0644);
  }
}



I haven't tested it, but it should recurively set the permissions of all directories to 755 and files to 644 starting from '/'. Change that to the directory you want to start from.



Dear rocky,

You can be life saver! :)

I tried your code
$dirs = array();
$dirs[] = '/img/p/';
while (($dir = array_pop($dirs)) != NULL)
{
  $files = scandir(array_pop($dirs));

  foreach ($files as $file)
  {
     if (is_dir($file))
     {
        chmod($file, 0755);
        $dirs[] = $file;
     }
     else
        chmod($file, 0644);
  }
} 



but got such mistakes:
Warning: scandir() [function.scandir]: Directory name cannot be empty in **/htdocs/test.php
Warning: Invalid argument supplied for foreach() in **/htdocs/test.php

Maybe you can advise what I am doing wrong?
Thank you anyway :)

Link to comment
Share on other sites

Just now finally I got straight answer from that bustards networksolutions. They say what they will not change default files permission to 644 and say what I should modify Prestashop code in order if I want what it will work in their server...

It is amazing! networksolutions really suck! 3 weeks they were playing around with me and just now answer clearly :(

Please, someone help me a little bit to modify Presta. How can I code Prestashop to create images with 644 permission.

Link to comment
Share on other sites

Try the following code:

$dirs = array();
$dirs[] = '/';

while (($dir = array_pop($dirs)) != NULL)
{
  $files = scandir(array_pop($dirs));

  foreach ($files as $file)
  {
     if (is_dir($file))
     {
        chmod($file, 0755);
        $dirs[] = $file;
     }
     else
        chmod($file, 0644);
  }
}



I haven't tested it, but it should recurively set the permissions of all directories to 755 and files to 644 starting from '/'. Change that to the directory you want to start from.



Dear rocky,

You can be life saver! :)

I tried your code
$dirs = array();
$dirs[] = '/img/p/';
while (($dir = array_pop($dirs)) != NULL)
{
  $files = scandir(array_pop($dirs));

  foreach ($files as $file)
  {
     if (is_dir($file))
     {
        chmod($file, 0755);
        $dirs[] = $file;
     }
     else
        chmod($file, 0644);
  }
} 



but got such mistakes:
Warning: scandir() [function.scandir]: Directory name cannot be empty in **/htdocs/test.php
Warning: Invalid argument supplied for foreach() in **/htdocs/test.php

Maybe you can advise what I am doing wrong?
Thank you anyway :)



I made a mistake in my code. I've updated my code, but I think it won't keep track of the current directory properly. You are better off just using cPanel to change the file permissions.
Link to comment
Share on other sites

Dear rocky,

Your code is almost working :) It's changing files permissions which are in same directory, but not in different. Maybe, I do something wrong or maybe it is some kind of security restrictions :)

Also, I talk with my client and he agree to change host. God bless him :D


Nickny, godaddy will be good for me, but my client had before problems with them :(

Please suggest any good host in America :) Also I will try to look in Presta forum.

Thank you mates for great support!

Link to comment
Share on other sites

Just for solving that topic.
I think there is many people in situation like is mine.

Maybe someone tries update Prestashop code in order to get images with 644 permissions?
I think it is enough to modify one or two line if you wish to get images with 644 permissions. But which lines??? :)

If yes, please post your solution here and I think you will save not one day for Presta community :)

Also, maybe someone know, why sometimes images created by Presta have 644, but usually 640?

Link to comment
Share on other sites

Try changing the returnDestImage function on line 225 of images.inc.php from:

function returnDestImage($type, $ressource, $filename)
{
   $flag = false;
   switch ($type)
   {
       case 'gif':
           $flag = imagegif($ressource, $filename);
           break;
       case 'png':
           $flag = imagepng($ressource, $filename, 7);
           break;
       case 'jpeg':
       default:
           $flag = imagejpeg($ressource, $filename, 90);
           break;
   }
   imagedestroy($ressource);
   return $flag;
}



to:

function returnDestImage($type, $ressource, $filename)
{
   $flag = false;
   switch ($type)
   {
       case 'gif':
           $flag = imagegif($ressource, $filename);
           break;
       case 'png':
           $flag = imagepng($ressource, $filename, 7);
           break;
       case 'jpeg':
       default:
           $flag = imagejpeg($ressource, $filename, 90);
           break;
   }
   chmod($filename, 0644);
   imagedestroy($ressource);
   return $flag;
}

Link to comment
Share on other sites

Try changing the returnDestImage function on line 225 of images.inc.php from:

function returnDestImage($type, $ressource, $filename)
{
   $flag = false;
   switch ($type)
   {
       case 'gif':
           $flag = imagegif($ressource, $filename);
           break;
       case 'png':
           $flag = imagepng($ressource, $filename, 7);
           break;
       case 'jpeg':
       default:
           $flag = imagejpeg($ressource, $filename, 90);
           break;
   }
   imagedestroy($ressource);
   return $flag;
}



to:

function returnDestImage($type, $ressource, $filename)
{
   $flag = false;
   switch ($type)
   {
       case 'gif':
           $flag = imagegif($ressource, $filename);
           break;
       case 'png':
           $flag = imagepng($ressource, $filename, 7);
           break;
       case 'jpeg':
       default:
           $flag = imagejpeg($ressource, $filename, 90);
           break;
   }
   chmod($filename, 0644);
   imagedestroy($ressource);
   return $flag;
}




THANK YOU ROCKY!!!!!!!!!!!!!! You save my life! I was just on last step to change host and you found solution!!!!
Mate you are great!!!!!

So for other people who belongs to Presta community. If you will have issue with pictures permissions on server, just add one line of code in images.inc.php file:

Add

chmod($filename, 0644);



before that code

imagedestroy($ressource);
return $flag;



That's it! Now you will have images with 0644 permissions!

Link to comment
Share on other sites

×
×
  • Create New...