How can I run a file from within PHP?

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
hvlav79
Forum Newbie
Posts: 2
Joined: Tue Aug 24, 2004 6:55 pm

How can I run a file from within PHP?

Post by hvlav79 »

Hi guys, I need your help!
I have written a piece of code that creates a file titled "playlist.m3u". I want to further develop the code so that the file "playlist.m3u" will be automatically played as soon as it is created through winamp. I have tried to use the exec() and system() functions but I couldn't get it to work. Are there any other commands I should know of? This is the code I have written:

<?php
if(isset($_POST['action']) AND $_POST['action']=1){
$filename = "c:/Temp/playlist.m3u";
$m3u=fopen($filename, "w") or die("cannot open $filename");
$selected=$_POST['selected'];
foreach($selected as $file){
fwrite($m3u,$file."\r\n");
}
fclose($m3u);
echo exec($filename);
}
?>

Is there someone who can help me?
Thanks in advance!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

php/apache is probably running under the SYSTEM user, which doesn't have access (directly) to Winamp. If you set the service to have interactive access to the desktop, or switch the user it runs under to one that has access rights to the drives, I believe it'll work.. although it's been a while since I've screwed around with that stuff. :)
Post Reply