help with this code please?
Posted on
16th Feb 2014 07:03 pm by
admin
Hello,
I am trying to build a remote upload script for my image hosting site.
I am using $_GET for testing purposes.
this would be the url you would visit:
Code: http://jnerocorp.com/imagehost/beta2/remote.php?imgurl=http://www.phpfreaks.com/media/images/forums/logo.png
This is the error I am getting:
Code: Invalid url given
Im not really sure if this code would even work though I havnt been able to test it
here is the code:
<?php
$imgurl = $_GET['img_url'];
// define the filename extensions you're allowing
define('ALLOWED_FILENAMES', 'bmp|gif|ico|jpg|png|tiff');
// define a directory the webserver can write to
define('IMAGE_DIR', '/images');
// check against a regexp for an actual http url and for a valid filename, also extract that filename using a submatch (see PHP's regexp docs to understand this)
if(!preg_match('#^http://.*([^/]+.('.ALLOWED_FILENAMES.'))$#', $imgurl, $m)) {
die('Invalid url given');
}
// try getting the image
if(!$img = file_get_contents($_GET['img_url'])) {
die('Getting that file failed');
}
$handle = fopen("$imgurl", "rb");
$filesize = fread($handle, filesize($myFile));
fclose($handle);
if($filesize <= 1048576) {
// try writing the file with the original filename -- note that this will overwrite any existing filename in the same directory -- that's up to you to check for
if(!file_put_contents(IMAGE_DIR.'/'.$m[1], $img)) {
die('Writing the file failed');
}
$uid = uniqid();
$image = $m[1].$img;
$master = $uid.$image;
rename("/images/".$m[1].$img."", "/images/".$master."");
$fullurl = "http://JneroCorp.com/imagehost/beta2/images/".$master."";
echo "<img src='$fullurl'>";
}
?>
No comments posted yet
Your Answer:
Login to answer
141
27
Other forums
MySql timezone
Code: $sql = "SELECT *, date_format(date, '%m/%d/%Y at %I:%i %p' )as date FROM comments WHERE t
Doubles are giving me problems
Ok so, first of all i made a double = 0.05, but when running the debugger it shows up as 0.04999. I
How to refresh a parent page from a modal popup
Hi,I have a modal popup in which I need to upload a file and store in the database should give a mes
Conditions of info record - Error
When i created GR (901) and PO create automatic my PBXX is obtain the net price of info record but
PHP Thumbnail Creation
Ok so i use this function to create thumbnails:
Code: [Select]function createthumb($name,$fil
FFmpeg Images 2 Video conversion problem ??
I got folder full of images , number of images = 600 , I want to make a video which plays one image
output_buffering so rewrite
I'm planning to rewrite some of my scripts so they don't have to use output buffering to accomplish
read integers that returns a negative or prints the average
Im trying to finish this homework assignment by tommarow afternoon and I keep getting stuck.
Wr
php calculate
this code echoes correctly the sum but the inserted result is 0??
Code: <?php
$TotalNum
exclude characters from counting?
Hello, I wanted to ask if you have a string like:
Code: $my_s='ASRGREGTGTR----REGREGRE+++RRRRRR..