I'm having trouble using wget with shell_exec. Looks as if shell_exec is working, I can do an ls command and get output to the browser but I'm not getting any results from wget. If I run the wget command directly in the terminal it works fine. I also opened all permissions on the uploading folder for testing.
The Script:

$title = "test";
$image = "http://www.wenworld.com/images/2004/12/02/1102013838_s.jpg";
UpdateImage($title, $image);

function UpdateImage($title, $image) {
	$filename = $_SERVER["SCRIPT_FILENAME"];
	$filename = ereg_replace("image_select.php", "", $filename);
	$filename = $filename."images/".date("U").".jpg";
	echo "wget '".$image."' -O '".$filename."'";
	echo "<hr>";
	$output = shell_exec("wget '".$image."' -O '".$filename."'") or die ("Problem downloading");
	echo $output;
}

The Output:

wget 'http://www.wenworld.com/images/2004/12/02/1102013838_s.jpg' -O '/Webserver/movielist/images/1102088059.jpg'
-----------------hr-----------------
Problem downloading

Any idea why I'm not getting this file /Webserver/movielist/images/1102088059.jpg?

Thanks

    Hi,

    try

    $output = shell_exec("wget '".$image."' -O '".$filename."' 2>&1");

    redirect stderr to stdout so php will see any error message wget (or the shell) displays.

    EDIT: You might need to use the full path to wget (e.g. /usr/bin/wget).

    Thomas

      Perfect, it was the full path. Thank you very much, that makes sence.

      Just incase anyone else has this same problem in OS X (what I use) the path is /sw/bin/wget .

      Thanks again.

        Write a Reply...