Page 1 of 1

help with the code ....it's not working

Posted: Fri Jun 15, 2007 3:41 pm
by vineet7kumar
hi
i wrote the following php code

Code: Select all

$rss_url= "http://www.ibnlive.com/xml/top.xml";
//$rss_url[2]="http://www.ibnlive.com/xml/world.xml";
//$rss_url[3]="http://www.ibnlive.com/xml/business.xml";
//$rss_url[4]="http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/world/rss.xml";
//$rss_url[5]="http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/technology/rss.xml";

$i=0;
//for($i=0 ;$i<6 ;$i++)
//{
//	echo $rss_url[$i];

$file = md5($rss_url);
//echo $file;
$inpath = "rss/$file.xml";
$outpath = "$file.html";
//echo $outpath;
copy($rss_url,$inpath);

//echo $path;
system('./a.out $inpath');
copy ("temphtm.html",$outpath);
echo "<a href='$outpath'> click$i</a><br>";
//}
note : a.out is the output file of a cpp program that takes as input a xml file and outputs a html file with the name
temphtm.html

when i run it i get the following error

Warning: copy(temphtm.html) [function.copy]: failed to open stream: No such file or directory..

though the cpp program is correct and working perfectly when i execute it .

also as you can see the comments , i was trying to use array , but it was not working....

please help,

thanks,
vineet[/i]

Posted: Fri Jun 15, 2007 4:14 pm
by nickvd
Dont mean to be rude, but did you even read the error?

Warning: copy(temphtm.html) [function.copy]: failed to open stream: No such file or directory..

It means that the file you are trying to copy "temphtm.html" doesnt exist...

Posted: Fri Jun 15, 2007 4:21 pm
by John Cartwright
mkdir() might be of interest

Posted: Fri Jun 15, 2007 10:04 pm
by vineet7kumar
to nickvd:

i don't mean to be rude but did u read the post ?....

i have mentioned that the program (cpp program whose output file is a.out) outputs a file "htmfile.html" and that the program is working perfectly alright when i run it separately !!!!

Posted: Sat Jun 16, 2007 9:05 am
by volka
note : a.out is the output file of a cpp program that takes as input a xml file and outputs a html file with the name
temphtm.html
vineet7kumar wrote:i have mentioned that the program (cpp program whose output file is a.out) outputs a file "htmfile.html"
Which one actually is it?

Please try

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', true);

$rss_url= "http://www.ibnlive.com/xml/top.xml";
//$rss_url[2]="http://www.ibnlive.com/xml/world.xml";
//$rss_url[3]="http://www.ibnlive.com/xml/business.xml";
//$rss_url[4]="http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/world/rss.xml";
//$rss_url[5]="http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/technology/rss.xml";

$i=0;
//for($i=0 ;$i<6 ;$i++)
//{
//      echo $rss_url[$i];

$file = md5($rss_url);
//echo $file;
$inpath = "rss/$file.xml";
$outpath = "$file.html";
//echo $outpath;
copy($rss_url,$inpath);

echo $inpath, ': ', file_exists($inpath) ? 'exists' : 'does not exists', "<br />\n";
echo 'a.out: ', file_exists('a.out') ? 'exists' : 'does not exists', "<br />\n";
echo 'a.out: ', is_readable('a.out') ? 'readable' : 'not readable', "<br />\n";
echo 'a.out: ', is_executable('a.out') ? 'executable' : 'not executable', "<br />\n";
//echo $path;
system('./a.out $inpath');
echo 'temphtm.html: ', file_exists('temphtm.html') ? 'exists' : 'does not exists', "<br />\n";
echo 'temphtm.html: ', is_readable('temphtm.html') ? 'readable' : 'not readable', "<br />\n";

copy ("temphtm.html",$outpath);
echo "<a href='$outpath'> click$i</a><br>";
//}
and post the output.

Posted: Sat Jun 16, 2007 9:11 pm
by smudge
I couldn't help but notice several things, vineet.
First, if you are trying to pass along the contents of an rss feed to a cpp program that sorts it into an html file, as I suspect you are doing, $file is a bunch of (almost) random numbers and letters derived from the url, not the file. I don't know what they are, because I don't feel like finding the md5 hash. Then you are sending rss/assortment-of-characters as input to your program. Last time I checked, it was next to impossible to reverse engineer the md5 hash, so you couldn't be reconstructing the file in your program (Although that would be a nifty trick). If you want to send the whole feed together, take a look at some filesystem functions like fopen() and fread().

Unless of course you are specifically trying to send the md5 hash, use md5_file(), then just ignore me :D

edit: In the future, a more descriptive title works better

Posted: Sat Jun 16, 2007 9:34 pm
by superdezign
If PHP tells you that the file doesn't exist, I'm pretty sure that it doesn't exist. Are you sure that there is a temphtm.html in the same folder as your PHP script?

It shouldn't matter that the C script is supposed to create the file, it should only matter that the file exists now. Nowhere in your script do you delete the file, so the file should still exist if it was created.

If it doesn't, then there is your problem.

Posted: Sat Jun 16, 2007 11:45 pm
by volka
@smudge: please note the line
copy($rss_url,$inpath);
in the original script. It's supposed to copy the contents of the rss document to a local file. The name of that local file is then passed to the C program a.out
system('./a.out $inpath');
Nothing wrong with that. (Expect that it might be easier to process the rss doc in php as well).

Posted: Wed Jun 20, 2007 6:12 pm
by smudge
ahh crap, It's always the little things that get you in the end. Sorry, I missed that line. :oops:

Posted: Thu Jun 21, 2007 11:17 am
by harsha
did you check the user:group permission of the internet user?

in Unix, generally whatever that is create by apache HTTP server is owned by the user "apache"

may the user who is running ./a.out does not have write permission for the directory where ./a.out resides.
chmod 777 and try again.

* also for the folder rss

Re: help with the code ....it's not working

Posted: Thu Jun 21, 2007 11:42 am
by RobertGonzalez
The manual page on system() has the following in the notes section:
Warning
If you are going to allow data coming from user input to be passed to this function, then you should be using escapeshellarg() or escapeshellcmd() to make sure that users cannot trick the system into executing arbitrary commands.

Note: If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends.

Note: When safe mode is enabled, you can only execute executables within the safe_mode_exec_dir. For practical reasons it is currently not allowed to have .. components in the path to the executable.

Warning
With safe mode enabled, the command string is escaped with escapeshellcmd(). Thus, echo y | echo x becomes echo y \| echo x.
Do any of these conditions apply to you?

Also, this line

Code: Select all

<?php
system('./a.out $inpath');
?>
Wouldn't that be a string evaluation instead of variable substitution because of the single quotes? Have you tried:

Code: Select all

<?php
system("./a.out $inpath");
?>
Or

Code: Select all

<?php
system('./a.out ' . $inpath);
?>
to see if that makes a difference?

Posted: Thu Jun 21, 2007 12:00 pm
by volka
uhh, I completely missed the single-quotes.
Maybe your a.out should write an error message when it can't read the data.

Posted: Thu Jun 21, 2007 4:44 pm
by smudge
I'm serious, it's the little things, volka :wink:

Posted: Thu Jun 21, 2007 4:50 pm
by RobertGonzalez
So is it working for you now? If so, what was the fix?