10

Currently I am using:

exec("zcat $filename", $output)

To uncompress a .Z type file but unfortunately my hosting company has now disabled this function.

Is there a workaround?

$pathtofile = "filename.lis.Z";
exec("zcat $pathtofile", $output);
MrWhite
  • 43,179
  • 8
  • 60
  • 84
Saad Bashir
  • 4,341
  • 8
  • 30
  • 60
  • Unfortunately the `compress` format `.Z` is not understood by zlib itself, so PHPs `gzuncompress()` won't work. If you can't use `exec` anymore, you'll have to adapt your file sources. Use `gzip` from now on. – mario Sep 27 '11 at 06:39
  • Unfortunately the files I am fetching are in .Z format. Unless there is an automatic way of converting them to gzip format I have to stick with .Z format. Do you know any host which allows exec() ? – Saad Bashir Sep 27 '11 at 06:47
  • 2
    Well, practically any professional hoster is using suexec rather than the safemode workaround. Note that your `zcat` was a special version with .Z support; you might need to reinstall that or use `uncompress -c $filename` rather. Also remember `escapeshellarg()` here. – mario Sep 27 '11 at 06:50
  • I haven't used escapeshellarg() but php.net help file says "Escape a string to be used as a shell argument" but the issue is i think in order to use it i still need system() or exec() but my hosting has blocked both. Do you know any service provide who might not give me such nightmares? – Saad Bashir Sep 27 '11 at 06:59
  • @mario how to use suexec? My hosting company told me that they have installed suexec but i can't still use exec() function so wondering how does it work now? – Saad Bashir Sep 28 '11 at 07:26
  • Has nothing do to with each other (suexec is a server setting, not a php function). Change your hoster. – mario Sep 28 '11 at 11:40
  • Dam! I can't find a host which is offering exec() i have tried searching for one even on google but no success so far – Saad Bashir Sep 28 '11 at 17:28
  • Just get a basic unmanaged VPS for $5/month and set up the stack yourself, and you won't have to worry about what the host disables. – Markus AO Mar 22 '22 at 07:25

4 Answers4

12

do this

echo ini_get("disable_functions");

to know if you are able to use one of the following:

system(); exec(); passthru(); shell_exec();

but if it's a shared hosting all the above are for sure blocked and you will have to find an alternative

Eli Y
  • 877
  • 16
  • 41
5

.Z files are LZW compression. If you can't run shell commands on your host, you can use an LZW PHP library. Here are two:

six8
  • 2,886
  • 21
  • 20
3
system($shell_command, $response_var);

So in your case:

system("zcat $filename", $output);
Atticus
  • 6,585
  • 10
  • 35
  • 57
0

In my case, disabled commands are

dl
sh2_exec
diskfreespace
disk_free_space
disk_total_space
escapeshellarg
escapeshellcmd
exec
highlight_file
link
lchgrp
lchown
passthru
pclose
popen
proc_close
proc_get_status
proc_nice
proc_open
proc_terminate
set_time_limit
shell_exec
show_source
symlink
system
mail
sendmail

So if one of those commands not blocked in your side, you may find a way to execute command.

msalihbindak
  • 592
  • 6
  • 21