I'm writing a small function to get the URL of an image and save to locally to server.
Here's the AJAX call (confirmed it's sending the correct URL to "getimdbpic.php" with firebug)
$.get("getimdbpic.php", { posterURL: data.Poster, movieTitle: data.Title },
function(picData){
alert("Data Loaded: " + picData);
});
The problem I'm having is with my PHP.
$url = $_GET['posterURL'];
$title = $_GET['movieTitle'];
file_put_contents($img, file_get_contents($url));
I simply can't get the values that are being passed. The file_put_contents throws an error stating that the "File name cannot be empty". (referring to $url being empty)
Edit: Fixed the casing, still not receiving values.
Make sure you're using the latest JQuery. I saw a very bizarre bug like regarding values not getting sent that was fixed by an upgrade.
EDIT: Might want to try a fallback to standard $.ajax()
since $.get()
is just a wrapper around it:
$.ajax({
url: "getimdbpic.php",
data: { posterURL: data.Poster, movieTitle: data.Title },
type: 'GET', // this is default, but just in case
success: function(picData){
alert("Data Loaded: " + picData);
}
});
You seem to be mixing up the case between posterURL
in the Javascript, and posterUrl
in the PHP.
Typo in the casing here:
$url = $_GET['posterURL'];