Bruce Gust
asked on
How to upload an internet file without an extension
I'm generating a QR code that I then want to upload to my server. Problem is, the image / qr code, while it looks great on the screen, doesn't have your typical URL in that there's no extension, at least as far as I can see.
Here's the image source code: https://chart.googleapis.com/chart?cht=qr&chs=250x250&chl=http://www.countryshowdown.com/app/view_contestants.php?id=53102&choe=UTF-8&chld=L
I can tell that it's a PNG when I look at the properties, but how do I convert the above mess into something that your typical upload script will understand and execute?
Right now, I'm using this ($url is the image source code you see above):
The result is the error that's cued to trigger when the code doesn't see a recognizable extension. How do I transform the above url into file name with an png extension that can then be uploaded?
Here's the image source code: https://chart.googleapis.com/chart?cht=qr&chs=250x250&chl=http://www.countryshowdown.com/app/view_contestants.php?id=53102&choe=UTF-8&chld=L
I can tell that it's a PNG when I look at the properties, but how do I convert the above mess into something that your typical upload script will understand and execute?
Right now, I'm using this ($url is the image source code you see above):
$name = basename($url);
list($txt, $ext) = explode(".", $name);
$name = $txt.time();
$name = $name.".".$ext;
echo $ext;
//check if the files are only image / document
if($ext == "jpg" or $ext == "png" or $ext == "gif" or $ext == "doc" or $ext == "docx" or $ext == "pdf")
{
//here is the actual code to get the file from the url and save it to the uploads folder
//get the file from the url using file_get_contents and put it into the folder using file_put_contents
$upload = file_put_contents("qr/$name",file_get_contents($url));
//check success
if($upload) echo "Success: <a href='qr/".$name."' target='_blank'>Check Uploaded</a>"; else "please check your folder permission";
}
else
{
echo "Please upload only image/document files";
}
The result is the error that's cued to trigger when the code doesn't see a recognizable extension. How do I transform the above url into file name with an png extension that can then be uploaded?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
I don't know. It looks like the script sends the image directly to the browser output stream, but without looking at the code that created the image and sent it to the browser, I would not be able to tell if it wrote the image file into a directory, too. Please post the script and I'll take a look.
ASKER
Never mind, Ray! I got it! Thanks so much!
Cool! Nite nite!
ASKER
Question: When bring up the image at http://www.countryshowdown.com/qr/QR_CODE_http_www_countryshowdown_com_contestant_php_id754.png, it shows up just fine, but the image itself isn't anywhere on my server. In other words, when I go looking in the qr directory, it isn't there. Should it be? Am I missing something?