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";
}
else
{
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?
PHP

Avatar of undefined
Last Comment
Ray Paseur
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

ASKER

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?
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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.
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

ASKER

Never mind, Ray! I got it! Thanks so much!
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Cool!  Nite nite!
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo