PDA

View Full Version : Little image uploader.



Excellent1
28-07-2008, 03:10 PM
Okay I know you people are/was going wild for image uploaders so I've built a simple one for you. I've put comments in so you can understand what to do etc. Remember to CHMOD your images folder to 0777(777) so the uploader can put your upload into that folder.

Yes, I know that it you can upload other file types which is a massive security risk so I only recommend this for little sites.


<?php
echo "<center>"; //We center the page.
$sitename = "sitename.com"; //Put your site url here.
switch ($_GET[page]) //We use the switch function to get the page.
{
default: //Self explanatory
echo "<form action='?page=upload' enctype='multipart/form-data' method='POST'>
Upload:
<input type='file' size='7' name='image' id='image'><br>
<input type='submit' name='submit' value='Upload'></form>";
break; //Break upload
case 'upload': //The upload case
$filename = $_FILES["img"]["name"];
$tmp_name = $_FILES["img"]["tmp_name"];
$img = "images/$filename"; //You can edit the images piece to where your images will be displayed
if (move_uploaded_file($tmp_name, "images/".$filename)) { //And here - we also move the file
echo "Image upload complete!<br><img src='$img'><br>
Forum ******?<br>
<input type='text' name='image' size='30' value='www.".$sitename.".com/files/upload/".$img."'>"; // We display that their file has been uploaded, show then the url and show them a picture of their upload
} else { //Lol the upload failed
die ("Don't bother uploading ever again.. seriously."); //True comment
}

break; //Break page

}
?>Have fun, or whatever.

Jahova
28-07-2008, 03:32 PM
Their could be many sercurity holes in this.
I am unfortunatley not going to use it, but it's helpful, +REP.

Excellent1
28-07-2008, 03:41 PM
Their could be many sercurity holes in this.
I am unfortunatley not going to use it, but it's helpful, +REP.Yeah, I urge people to lock the folder so 'hackers' can't upload files. It's just a little file uploader for websites who don't want to go ramming through cPanel all the time (the ability to upload other file types comes in handy:P)

michaelish
28-07-2008, 04:25 PM
+rep for giveing to the forum

Protege
28-07-2008, 05:20 PM
Okay I know you people are/was going wild for image uploaders so I've built a simple one for you. I've put comments in so you can understand what to do etc. Remember to CHMOD your images folder to 0777(777) so the uploader can put your upload into that folder.

Yes, I know that it you can upload other file types which is a massive security risk so I only recommend this for little sites.


<?php
echo "<center>"; //We center the page.
$sitename = "sitename.com"; //Put your site url here.
switch ($_GET[page]) //We use the switch function to get the page.
{
default: //Self explanatory
echo "<form action='?page=upload' enctype='multipart/form-data' method='POST'>
Upload:
<input type='file' size='7' name='image' id='image'><br>
<input type='submit' name='submit' value='Upload'></form>";
break; //Break upload
case 'upload': //The upload case
$filename = $_FILES["img"]["name"];
$tmp_name = $_FILES["img"]["tmp_name"];
$img = "images/$filename"; //You can edit the images piece to where your images will be displayed
if (move_uploaded_file($tmp_name, "images/".$filename)) { //And here - we also move the file
echo "Image upload complete!<br><img src='$img'><br>
Forum ******?<br>
<input type='text' name='image' size='30' value='www.".$sitename.".com/files/upload/".$img."'>"; // We display that their file has been uploaded, show then the url and show them a picture of their upload
} else { //Lol the upload failed
die ("Don't bother uploading ever again.. seriously."); //True comment
}

break; //Break page

}
?>Have fun, or whatever.

and... you called my coding messy - LOL

Excellent1
28-07-2008, 05:29 PM
and... you called my coding messy - LOLProblem is your code is dirty 99.9% of the time, all mine needs doing is cleaning up:

<?php
echo "<center>"; //We center the page.

$sitename = "sitename.com"; //Put your site url here.

switch ($_GET[page]) //We use the switch function to get the page.
{

default: //Self explanatory

echo "<form action='?page=upload' enctype='multipart/form-data' method='POST'>
Upload:
<input type='file' size='7' name='image' id='image'><br>
<input type='submit' name='submit' value='Upload'></form>";
break; //Break upload

case 'upload': //The upload case

$filename = $_FILES["img"]["name"];
$tmp_name = $_FILES["img"]["tmp_name"];
$img = "images/$filename"; //You can edit the images piece to where your images will be displayed
if (move_uploaded_file($tmp_name, "images/".$filename))
{ //And here - we also move the file

echo "Image upload complete!<br><img src='$img'><br>
Forum ******?<br>
<input type='text' name='image' size='30' value='www.".$sitename.".com/files/upload/".$img."'>"; // We display that their file has been uploaded, show then the url and show them a picture of their upload
}
else
{ //Lol the upload failed
die ("Don't bother uploading ever again.. seriously."); //True comment
}
break; //Break page
}
?>

Protege
28-07-2008, 05:34 PM
though you have yet to prove that my coding is messy and your coding is still messy...

You really have no factual evidence, you see there is one code on Habbox that I would consider messy - but thats it.

Seriously how many times do I have to say this, stick to your high IQ **** and go write some poems about how crap you are at any computing language you attempt.

Heres some PHP i did today - messy - suck my ****



function updateCode ( $id, $code )
{
if ( ( $id == '' ) || ( $code == '' ) )
{
echo ( 'blank' );
}
elseif ( ( $id != '' ) || ( $code != '' ) )
{
if ( is_numeric( $code ) )
{
$mysqlQuery = mysql_query ( 'UPDATE `negair_stock`.`goods` SET `goods-productcode` = "' . cleanString ( $code ) . '" WHERE `goods`.`id` = "' . cleanString ( $id ) . '" LIMIT 1 ;' );
if ( $mysqlQuery )
{
echo ( 'true' );
}
else
{
echo ( 'false' );
}
}
}
}
Code shouldnt need to be "cleaned" up, should be typed clean when your coding it. All your doing is wasting more time noob.

Thats PHP, heres some javascript:



function changeProductcode ( id, oldcode )
{
var code = prompt( 'Please enter the new product code below!', '' );
if ( code == '' )
{
alert ( 'Please enter a value for this field - No blank inputs allowed!' );
}
else if ( code != '' )
{
if ( checkInt( code ) )
{
var answer = confirm ( 'Are you sure you want to update the product code from ' + oldcode + ' to ' + code );
if ( answer )
{
if ( window.XMLHttpRequest )
{
httpRequest = new XMLHttpRequest();
}
else if ( window.ActiveXObject )
{
httpRequest = new ActiveXObject ( 'Microsoft.XMLHTTP' );
}

httpRequest.onreadystatechange = checkReturn;
httpRequest.open ( 'GET', 'updatepcode.php?pcode=' + code + '&id=' + id, true );
httpRequest.send( null );
}
}
else
{
alert ( 'Sorry, that value you placed in wasn\'t an integer, please only enter integer values for this field!' );
}
}
}

Excellent1
28-07-2008, 05:46 PM
Well done on posting some semi clean code you probably went through and tidied up:eusa_clap

I really think you're a homosexual due to you always repeated the same boring phrase over and over again that people used to use in year 7, "suck my ****".

If you're going to be a selfish son of a ***** I urge you to use that mop on top of your head as a toilet plunger and do something decent with your life.. Perhaps get one? This thread is for people who want to upload images, not silly cry babies with issues.

Edited by ,Jess, (Forum Super Moderator): Please do not be rude towards other forum members.

Protege
28-07-2008, 05:55 PM
"Semi-clean", you make me laugh... I don't need to go through my code and clean it up I type it clean so If I have to go debug something in it, I can easily do that unlike you that would spend sitting there for hours figuring why an error is occurring.

Im obviously homosexual to your standards, and like some 7 year old? Ahahaha make me laugh even more man - That **** I say I mean, you can kiss my *** - thats a better one for you to flame about. I swear your the guy who goes "imbecile" all the time, that gets boring too.

My mop on my head, that was a picture from last year, I show that cause I love the fact how people like you take the piss out of it, I know I look like a sexy emo in it thats why I'm showing you - be jealous LOL but seriously I have a high self-esteem I dont get put down by people like you.

I show that picture to everyone, think I care if you posted everywhere? its on deviantart for **** sake, i'm art bro and why the **** are you talking about my hair? Is that the only thing you can insult me on, I thought you where much more intelligent.

Anyway, your script sucks, everything you do sucks - you fail in this forum sector, just get out.

Edited by Invent (Forum Moderator): Please don't be rude.

Excellent1
28-07-2008, 06:09 PM
"Semi-clean", you make me laugh... I don't need to go through my code and clean it up I type it clean so If I have to go debug something in it, I can easily do that unlike you that would spend sitting there for hours figuring why an error is occurring.

Im obviously homosexual to your standards, and like some 7 year old? Ahahaha make me laugh even more man - That **** I say I mean, you can kiss my *** - thats a better one for you to flame about. I swear your the guy who goes "imbecile" all the time, that gets boring too.

My mop on my head, that was a picture from last year, I show that cause I love the fact how people like you take the piss out of it, I know I look like a sexy emo in it thats why I'm showing you - be jealous LOL but seriously I have a high self-esteem I dont get put down by people like you.

I show that picture to everyone, think I care if you posted everywhere? its on deviantart for **** sake, i'm art bro and why the **** are you talking about my hair? Is that the only thing you can insult me on, I thought you where much more intelligent.

Anyway, your script sucks, everything you do sucks - you fail in this forum sector, just get out.So basically you wasted around 5 minutes of time trying to get me to react to that stupid bunch of text? I'll reply when you learn how to construct a decent insult :)

Protege
28-07-2008, 06:10 PM
was around 9 minutes, i was laughing for them 4 minutes say.

and if you think your good at psychology, you just failed your grades right then.

Source
28-07-2008, 06:22 PM
Please just grow up both of you. Your 16 fgs... not 9.

Excellent1
28-07-2008, 06:24 PM
Please just grow up both of you. Your 16 fgs... not 9.Hey hey, it isn't me whos trying to get a reaction ;) By the way guys, I'll update the security on request if wanted.

Meti
28-07-2008, 06:33 PM
Nice script Lucas. Thanks for bringing this to the forum ;)

Protege
28-07-2008, 06:36 PM
The way you wanted to publish this as having a htaccess password protection then no more security is needed unless you want it for images only but I can't see nothing wrong with it being anything you want.

Agnostic Bear
28-07-2008, 06:39 PM
Hey what's with all the
if( what == what )

and the

{
$variable
}

ya'll never used to do that before i started :(

iTech
28-07-2008, 06:39 PM
The code James posted earlier, wasn't messy at the beginning.
As I was viewing it all the way through :P

Good script, but as stated needs a tighten in security.

Excellent1
28-07-2008, 06:55 PM
Nice script Lucas. Thanks for bringing this to the forum ;)No problem :)


The way you wanted to publish this as having a htaccess password protection then no more security is needed unless you want it for images only but I can't see nothing wrong with it being anything you want.htaccess or directory lock I would have thought.


Hey what's with all the
if( what == what )and the

{
$variable
}
ya'll never used to do that before i started :(Looks good:P

Calon
30-07-2008, 06:01 AM
Their could be many sercurity holes in this.
I am unfortunatley not going to use it, but it's helpful, +REP.
How did you guess that, by seeing there's barely any code?!

Also, don't take this offensivly.. but is this a tutorial or a release, if so why comment it so much?

Excellent
31-07-2008, 07:44 PM
How did you guess that, by seeing there's barely any code?!

Also, don't take this offensivly.. but is this a tutorial or a release, if so why comment it so much?Well tutorial really.

Calon
31-07-2008, 07:54 PM
Well tutorial really.
Fair enough. :P

Excellent
31-07-2008, 07:56 PM
It was more of a; Okay I've built this little uploader to make life easier for myself so I might aswell release it whilst at the same time try to show people how things work :P

Want to hide these adverts? Register an account for free!