Jump to content

issues with system()


Imaulle

Recommended Posts

Hello,

 

I have the following code

 

 

class Uploads extends Controller
{
public function __construct()
{
  parent::__construct();

  if (empty($_FILES))
  {
   log_message('error', 'Uploads - files empty');
   exit('No files uploaded');
  }

  ini_set('memory_limit', '128M');

  $this->load->helper('file');
  $this->load->helper('helpers');
  $this->load->model('uploads_model');

}

public function font_handler()
{
  $this->uploads_model->font_handler();
}

}

class Uploads_model extends Model
{
    public function font_handler()
    {
  $config = array(
   'max_size'     => '8388',
   'allowed_types' => 'ttf',
   'upload_path'   => 'assets/fonts/'
  );

  $this->load->library('upload', $config);

  if ($this->upload->do_upload('Filedata'))
  {
   $file = $this->upload->data();
   $jsFile = $file['raw_name'].'.js';
   $query = $this->db->where('location', 'menuFont')->get('fonts')->row();

   if ($query->customFile != '' && file_exists('assets/fonts/'.$query->customFile))
         {
    unlink('assets/fonts/'.$query->customFile);
   }

   $path    = getcwd() . '/assets/fonts/cufon/convert.php';
   $command = 'php ' . $path . ' -u "U+??" ' . $file['full_path'] . ' 1> ' . getcwd() . '/assets/fonts/' . $jsFile;

   system($command);
  }
}

}

 

 

Ok so, the ttf file is uploaded correctly and I can run $command from the command promt in putty and it works perfect, but when I try to run the same command from system() the js file just contains (from the controller) "No files uploaded" I have no idea why this is happening? Anyone have any ideas?  Also one thing i'm not sure about is if it should be 1> or > when creating the js file?!?

 

 

Thanks guys!

Link to comment
Share on other sites

You got too much going on and not enough information provided. The issue may happen in the code you gave us, but your use of other functions can be what's causing the problem. So if you think the issue is with your system() function, then we'd need to see that, not the code making use of the function.

Link to comment
Share on other sites

I did a write_file('text.txt', $command) and it did this:

 

php /home/morganb/public_html/html_projectDT/assets/fonts/cufon/convert.php -u "U+??" /home/morganb/public_html/html_projectDT/assets/fonts/Gill_Sans.ttf 1> /home/morganb/public_html/html_projectDT/assets/fonts/Gill_Sans.js

 

which is correct as far as the cufon convert.php is concerned. However the Gill_Sans.js file only contains the exit() from the controller "no files uploaded"

Link to comment
Share on other sites

It is possible the the PATH environment variable for the webserver does not include the path for the php command-line executable. Find out where it actually is and change the command you execute to include the full path for php

 

/usr/bin/php myphpscript.php ...

 

Link to comment
Share on other sites

hmm nope that is not it. from the command line it only works when I do this:

 

php /home/morganb/public_html/html_projectDT/assets/fonts/cufon/convert.php -u "U+??" /home/morganb/public_html/html_projectDT/assets/fonts/Gill_Sans.ttf 1> /home/morganb/public_html/html_projectDT/assets/fonts/Gill_Sans.js

 

if I do /usr/bin/php the convert.php throws an error. Is there a different function I should use other than system()? I don't get how the above command works in putty but not when called from system() :\

Link to comment
Share on other sites

When a system() call works from the command-line (in putty) but does not work from a webpage, the problem usually has to do with who and what is running. When run from the command line, the script is running as you (or whoever you logged in as) with your access rights and your environment. When run from a webpage, it is running as the webserver NOT as you. On a well configured system, the webserver user has tightly restricted privileges and environment. You have to figure out the difference between these two environments and work around it.

 

Try creating a script with JUST a call to phpinfo(). Run it from putty and redirect the output to a file. Then run it from a webpage with the output redirected. Compare the two files. Look especially at the ENV PATH values and the PHP include paths. Add a call to system("id"); to the script. That should tell you the user running the script as well as the groups it belongs to.

 

Check the permissions on the directories and files you are trying to access in the system() call -- the webserver user (or group) will have to have read access to the script you are running and will have to have write access to any directories and files it needs to write to, it will need execute access to any directories and sub-directories it needs to traverse (access).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.