Imaulle Posted April 12, 2012 Share Posted April 12, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/260828-issues-with-system/ Share on other sites More sharing options...
Imaulle Posted April 12, 2012 Author Share Posted April 12, 2012 so basically what is happening is... the file is uploaded, then somehow it's like the system() call causes the url to be reloaded?!?!? soooooooooo confused how that could be happening.... Quote Link to comment https://forums.phpfreaks.com/topic/260828-issues-with-system/#findComment-1336871 Share on other sites More sharing options...
creata.physics Posted April 13, 2012 Share Posted April 13, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260828-issues-with-system/#findComment-1336939 Share on other sites More sharing options...
Imaulle Posted April 13, 2012 Author Share Posted April 13, 2012 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" Quote Link to comment https://forums.phpfreaks.com/topic/260828-issues-with-system/#findComment-1336953 Share on other sites More sharing options...
Imaulle Posted April 13, 2012 Author Share Posted April 13, 2012 btw I should maybe mention this is in Codeigniter. However no one from the CI forum could offer any input so now I'm trying here... Quote Link to comment https://forums.phpfreaks.com/topic/260828-issues-with-system/#findComment-1336956 Share on other sites More sharing options...
Imaulle Posted April 13, 2012 Author Share Posted April 13, 2012 sorry bump~ anyone? I'm banging my head against the wall with this one Quote Link to comment https://forums.phpfreaks.com/topic/260828-issues-with-system/#findComment-1337186 Share on other sites More sharing options...
DavidAM Posted April 13, 2012 Share Posted April 13, 2012 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 ... Quote Link to comment https://forums.phpfreaks.com/topic/260828-issues-with-system/#findComment-1337216 Share on other sites More sharing options...
Imaulle Posted April 14, 2012 Author Share Posted April 14, 2012 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() :\ Quote Link to comment https://forums.phpfreaks.com/topic/260828-issues-with-system/#findComment-1337224 Share on other sites More sharing options...
DavidAM Posted April 14, 2012 Share Posted April 14, 2012 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). Quote Link to comment https://forums.phpfreaks.com/topic/260828-issues-with-system/#findComment-1337248 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.