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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vineet7kumar
Forum Newbie
Posts: 6
Joined: Sun Jun 03, 2007 3:10 pm

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

Post 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]
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post 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...
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

mkdir() might be of interest
vineet7kumar
Forum Newbie
Posts: 6
Joined: Sun Jun 03, 2007 3:10 pm

Post 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 !!!!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
smudge
Forum Contributor
Posts: 151
Joined: Sun May 20, 2007 12:13 pm

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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).
smudge
Forum Contributor
Posts: 151
Joined: Sun May 20, 2007 12:13 pm

Post by smudge »

ahh crap, It's always the little things that get you in the end. Sorry, I missed that line. :oops:
User avatar
harsha
Forum Contributor
Posts: 103
Joined: Thu Jul 11, 2002 1:35 am
Location: Bengaluru (Bangalore) > Karnataka > India

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

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

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
smudge
Forum Contributor
Posts: 151
Joined: Sun May 20, 2007 12:13 pm

Post by smudge »

I'm serious, it's the little things, volka :wink:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

So is it working for you now? If so, what was the fix?
Post Reply