Converting a "common upload field" to one that accepts url links
Hello everyone,
Have a lil issue I cant seem to figure out.
I have a basic upload box which works great, but i want a way to pull thumbnails from embedded videos. well I have figured out how to do this, but the image i need is stored in url form. (http://www.site.com/image.jpg) My upload field only accepts files already on the computer, not external links to images.
I already have a script that uploads the image and does a ton of stuff to it, and I dont want to edit it much. My problem is getting the script to accept a external image url, instead of a file location.
code for the upload field:
| <input class="filebox" size="36" type="file" id="uploadthumb" name="uploadthumb"<?php if (isset($_POST['uploadthumb'])) { echo "value='".stripslashes($_POST['uploadthumb'])."'" ; } ?>/> |
script code:
$dbthumb = ''; if (! empty($_FILES['uploadthumb']['tmp_name'])) { $thumbfilename = str_replace(" ", "_", $_FILES['uploadthumb']['name']) ; $thumbfilename = md5(uniqid(rand())).'_'.$thumbfilename ; $maxsize = 10000 ; if ($_FILES['uploadthumb']['size'] < $maxsize * 1024) { $thumbfilename = str_replace(" ", "_", $_FILES['uploadthumb']['name']) ; $thumbfilename = md5(uniqid(rand())).'_'.$thumbfilename ; //upload the thumbnail if one was specified $maxsize = 10000 ; if ($_FILES['uploadthumb']['size'] < $maxsize * 1024) { $filename = $_FILES['uploadthumb']['name'] ; $filename_without_ext = $filename ; $ext_pos = strrchr($filename, '.') ; if ($ext_pos !== false) { $filename_without_ext = substr($filename, 0, -strlen($ext_pos)) ; } $ext = strtolower(substr($filename, strrpos($filename, '.') + 1)) ; //img ext removed here $img_exts = array('nowayhoe') ; if (array_search($ext, $img_exts) !== FALSE) { if (move_uploaded_file($_FILES['uploadthumb']['tmp_name'], 'uploads/thumbs/'.$thumbfilename)) { $thumb_name = str_replace("'","",$title); //createThumb($thumbfilename, getSetting("avatar_h", $db), getSetting("avatar_w", $db), 'uploads/thumbs/', 'uploads/thumbs/', $title.".jpg") ; createThumb($thumbfilename, getSetting("savatar_h", $db), getSetting("savatar_w", $db), 'uploads/thumbs/', 'uploads/thumbs/', $title.".jpg") ; $dbthumb = $thumb_name ; } } else { $errorresult = "th" ; } } } }
basically I want to be able to paste a "http://www.site.com/image.jpg" into the what is not a upload field and have the script pull the image and package it in a way so that it can be used in my current script.
I found a few how tos for uploading external links, such as:
$contents= file_get_contents('http://mydomain.com/folder/image.jpg');
but just not sure how to integrate them into my current script or the upload field, I know i cant change it to text field, so how do I get the link in there? or can I... confused, everyhitng ive tried hasnt worked so far!
thanks much for any help you might provide!
