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
Firefox displaying PHP source code??
Currently testing a site thats almost built, am going to be including php on a sidebar on all pages
Redirecting Admin
In my members table, I have a field called "perm" and it's set to zero for all members. Ho
pointer 102 question
I read a book
1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
how to get sn motherboard
Hello.
I want to get serial number motherboard, cpu and else hardware.
Can You show me sam
Variable uses and placement
I'm new to PL/SQL and am trying to learn about variable valid uses/placement (any pointers to any do
My query is being run with no results.
I have this.
Code: function DropUser($duser_id, $user_email, $user_username) {
set xml path in flash when xml created in memorystream and webrequest
i am creating an xml file using memory stream and i want to load this xml file into the flash on cli
FlashVar function how to insert variables
Hi guys. Im new in this forum and also new in php programming. Can you help me about this code?
<
Function
How can I make this function that once you click the link in the code it takes you to a new page wit
Looking for help reading a .txt or .ini file and outputting the info.
I have a file called Info.ini and It has the following info:
Code: [General]
Online=0
I wou