Hi,
I'm using PHP 5 on Linux. I have a function that checks for file type
by doing the following:
$cmd = "file $p_input_file";
exec("$cmd 2>&1", $output, $return);
However if the file "$p_input_file" contains spaces, the command
doesn't work properly (I would need to insert a "\" before the space
for it to work). I figure there are probably some other characters in
the file name that would screw up the command. Is there a predefined
way of escaping the file names or do I need to just do a generic
search and replace on all the special characters I can think of?
Thanks, - Dave 4 3739
Hi, la***********@zipmail.com wrote:
$cmd = "file $p_input_file";
exec("$cmd 2>&1", $output, $return);
However if the file "$p_input_file" contains spaces, the command
doesn't work properly (I would need to insert a "\" before the space
for it to work). I figure there are probably some other characters in
the file name that would screw up the command. Is there a predefined
way of escaping the file names or do I need to just do a generic
search and replace on all the special characters I can think of?
escapeshellarg(). It's even in the same manual section as exec() :-)
-hwh
..oO(la***********@zipmail.com)
>I'm using PHP 5 on Linux. I have a function that checks for file type by doing the following:
$cmd = "file $p_input_file";
exec("$cmd 2>&1", $output, $return);
However if the file "$p_input_file" contains spaces, the command doesn't work properly (I would need to insert a "\" before the space for it to work). I figure there are probably some other characters in the file name that would screw up the command. Is there a predefined way of escaping the file names or do I need to just do a generic search and replace on all the special characters I can think of?
escapeshellarg()
escapeshellcmd()
Micha
On Aug 4, 9:36*am, Michael Fesser <neti...@gmx.dewrote:
.oO(laredotorn...@zipmail.com)
I'm using PHP 5 on Linux. *I have a function that checks for file type
by doing the following:
* * * * * * * *$cmd = "file $p_input_file";
* * * * * * * *exec("$cmd 2>&1", $output, $return);
However if the file "$p_input_file" contains spaces, the command
doesn't work properly (I would need to insert a "\" before the space
for it to work). *I figure there are probably some other characters in
the file name that would screw up the command. *Is there a predefined
way of escaping the file names or do I need to just do a generic
search and replace on all the special characters I can think of?
escapeshellarg()
escapeshellcmd()
Micha
Thanks but I think I'm still doing something wrong. I have
$p_input_file = "/home/me/Toad Getting Started
Guide.pdf";
$cmd = escapeshellcmd("file $p_input_file");
print "cmd: $cmd<BR>\n"; # outputs 'cmd: file /home/
me/Toad Getting Started Guide.pdf'
Shouldn't the command print out as
cmd: file /home/laredotornado/Toad\ Getting\ Started\ Guide.pdf
? - Dave
*** la***********@zipmail.com escribió/wrote (Mon, 4 Aug 2008 12:23:06
-0700 (PDT)):
$p_input_file = "/home/me/Toad Getting Started
Guide.pdf";
$cmd = escapeshellcmd("file $p_input_file");
print "cmd: $cmd<BR>\n"; # outputs 'cmd: file /home/
me/Toad Getting Started Guide.pdf'
Try:
$cmd = 'file ' . escapeshellarg($p_input_file);
I've never really understood what escapeshellcmd() is supposed to do.
Apparently, it tries to prevent user input from doing harm, but it doesn't
care about making the command actually work.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor en cubitos: http://www.demogracia.com
-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave Moore |
last post by:
Hi All,
Can anybody point me to a FAQ or similar that describes what all this
stuff is about please?. I'm interfacing with a MySQL database if that's
relavent. I've read a couple of books which...
|
by: Aloysio Figueiredo |
last post by:
I need to replace every ocurrence of '/' in s by '\/'
in order to create a file named s. My first attempt
was:
s = '\/'.join(s.split('/'))
but it doesn't work:
>>> s = 'a/b'
>>> s =...
|
by: felciano |
last post by:
Hi --
I am trying to use the csv module to parse a column of values
containing comma-delimited values with unusual escaping:
AAA, BBB, CCC (some text, right here), DDD
I want this to come...
|
by: Joe Price |
last post by:
Hi all
I've formatted one of my xml files for viewing through a web browser
using xsl.
It works fine in Internet Explorer, however when I use Netscape6 or
Opera to view the same page the...
|
by: agarwalpiyush |
last post by:
Hello,
I am going nuts with trying to get the following to work:
This is what I intend to do: I have a line in /etc/syslog.conf which I
need to delete based on ip-address provided to me in a...
|
by: Troot |
last post by:
Hi All,
I was wondering if someone could clear this up for me. I have
constructed a sample for a bigger problem I'm having. So, given the xml
file:
<?xml-stylesheet href="test.xsl"...
|
by: Frank Rizzo |
last post by:
Hello,
I'd like to have the following structure in my XML file
<lname, _fname, _minit>
<status>it is all good</status>
</lname, _fname, _minit>
But apparently, there is a problem with...
|
by: Jon |
last post by:
Hi,
I used XslCompiledTransform with the following Xsl file. The <xsl:text
disable-output-escaping="yes"does not work when using XslCompiledTransform
to do the trnasform (namely the output...
|
by: Taras_96 |
last post by:
Hi everyone,
I'm having a bit of trouble understanding the purpose of escaping
nulls, and the use of addcslashes.
Firstly, the manual states that:
"Strictly speaking, MySQL requires only...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |