troubleshooting Question

How to upload an internet file without an extension

Avatar of Bruce Gust
Bruce GustFlag for United States of America asked on
PHP
5 Comments1 Solution337 ViewsLast Modified:
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):

$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?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros