Avatar of Bruce Gust
Bruce GustFlag for United States of America 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):

$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";
echo "Please upload only image/document files";

Open in new window

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?

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
Ray Paseur

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Bruce Gust

Ray, not that I would expect anything less from one of my favorite ninjas, but this awesome!

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?
Ray Paseur

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.
Bruce Gust

Never mind, Ray! I got it! Thanks so much!
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Ray Paseur

Cool!  Nite nite!