PDA

View Full Version : Simple image upload script



Forge
04-12-2007, 06:20 PM
I got bored so i made this simple image upload script!

Preview
http://img107.imageshack.us/img107/5159/imgprevmp0.png

Code


<html>
<head>
<title>Yoursite</title>
<style>
body {
font-family: Franklin Gothic Book;
font-size: 12px;
font color: #efefef;
}
input {
border: 1px solid #efefef;
font-family: Franklin Gothic Book;
font-size: 12px;
font color: #efefef;
}
img {
border: 1px solid #efefef;
}
</style>
</head>
<form action="imageupload.php" method="post" enctype="multipart/form-data">
Browse a File to Upload:<br>
<input type="file" name="filetoupload"><br>
<input type="hidden" name="MAX_FILE_SIZE" value="<?echo $size_bytes; ?>">
<br>
<input type="Submit" value="Upload File">
</form>
<?php
$upload_dir = "images/public"; //change to whatever you want.
// files less than 1MB
$size_bytes = 10000000000; //bytes will be uploaded
$limit_file_type = "yes"; //Do you want to limit the types of files uploaded. (yes/no)
// specify file types.
$allowed_file_type = array('image/gif',
'image/pjpeg',
'image/jpeg',
'image/png',
'image/PNG',
'image/bmp',
'image/jpg');
//check if the directory exist or not.
if (!is_dir("$upload_dir")) {
die ("The directory <b>($upload_dir)</b> doesn't exist");
}
//check if the directory is writable.
if (!is_writeable("$upload_dir")){
die ("The directory <b>($upload_dir)</b> is NOT writable, Please Chmod (777)");
}
//Check first if a file has been selected
//is_uploaded_file('filename') returns true if
//a file was uploaded via HTTP POST. Returns false otherwise.
if (is_uploaded_file($_FILES['filetoupload']['tmp_name']))
{//begin of is_uploaded_file
//Get the Size of the File
$size = $_FILES['filetoupload']['size'];
//Make sure that $size is less than 1MB (1000000 bytes)
if ($size > $size_bytes)
{
echo "File Too Large. File must be <b>$size_bytes</b> bytes.";
exit();
}
//check file type
if (($limit_file_type == "yes") && (!in_array($_FILES['filetoupload']['type'],$allowed_file_type)))
{
echo"wrong file type";
exit();
}
// $filename will hold the value of the file name submetted from the form.
$filename = $_FILES['filetoupload']['name'];
// Check if file is Already EXISTS.
if(file_exists($upload_dir.$filename)){
echo "
<table border='1' style='border-collapse: collapse' bordercolor='#FF0000' bgcolor='#EFEFEF'>
<tr>
<td><font family='Franklin Gothic Book' size='1' color='#FF0000'>$filename already exists on our servers!</font></td>
</tr>
</table>
";
exit();
}
//Move the File to the Directory of your choice
//move_uploaded_file('filename','destination') Moves afile to a new location.
if (move_uploaded_file($_FILES['filetoupload']['tmp_name'],$upload_dir.$filename)) {
//tell the user that the file has been uploaded and make him alink too;).
echo "<img src='$upload_dir$filename'> <br>
Direct link<br>
<input size='60' value='$upload_dir$filename'>";
exit();
}
else
{
//Print error
echo "
<table border='1' style='border-collapse: collapse' bordercolor='#FF0000' bgcolor='#EFEFEF'>
<tr>
<td><font family='Franklin Gothic Book' size='1' color='#FF0000'>There was a problem moving your file</font></td>
</tr>
</table>
";
exit();
}
}//end of is_uploaded_file

?>

Pazza
04-12-2007, 06:24 PM
Seem's very complicated - some are quite simple.

Well done though, this is the first of many things

Forge
04-12-2007, 06:38 PM
Most of the code is for when there are config, errors etc.

Invent
04-12-2007, 06:41 PM
http://www.pixel2life.com/forums/index.php?showtopic=1454&mode=threaded&pid=118142

Forge
04-12-2007, 06:43 PM
:) yup! you will see how i have jazzed this baby up!

Invent
04-12-2007, 06:44 PM
You've added a few minor css properties ;s

Oh and you claimed you made it.

Forge
04-12-2007, 06:45 PM
and code!
oh and so i have, my bad! ill change that

EDIT: oh bugger i cant. anyway i didnt make it i ment to put edit it. Many many things were going through my head when i was posting! and Making of Pixel2life created this script i just decorated it for him seen as though he couldnt be bothered! :)

Implosion
04-12-2007, 06:45 PM
Not very much done.

You added css style.
LOL.

so, you didn't "make" it.
You infact, edited it.

Forge
04-12-2007, 06:48 PM
read my above post pal.

Invent
04-12-2007, 06:52 PM
and code!

Please point out what code you have added apart from echoing out some HTML.

.L!nK.
04-12-2007, 06:52 PM
I got bored so i made this simple image upload script!

Preview
http://img107.imageshack.us/img107/5159/imgprevmp0.png

Code


<html>
<head>
<title>Yoursite</title>
<style>
body {
font-family: Franklin Gothic Book;
font-size: 12px;
font color: #efefef;
}
input {
border: 1px solid #efefef;
font-family: Franklin Gothic Book;
font-size: 12px;
font color: #efefef;
}
img {
border: 1px solid #efefef;
}
</style>
</head>
<form action="imageupload.php" method="post" enctype="multipart/form-data">
Browse a File to Upload:<br>
<input type="file" name="filetoupload"><br>
<input type="hidden" name="MAX_FILE_SIZE" value="<?echo $size_bytes; ?>">
<br>
<input type="Submit" value="Upload File">
</form>
<?php
$upload_dir = "images/public"; //change to whatever you want.
// files less than 1MB
$size_bytes = 10000000000; //bytes will be uploaded
$limit_file_type = "yes"; //Do you want to limit the types of files uploaded. (yes/no)
// specify file types.
$allowed_file_type = array('image/gif',
'image/pjpeg',
'image/jpeg',
'image/png',
'image/PNG',
'image/bmp',
'image/jpg');
//check if the directory exist or not.
if (!is_dir("$upload_dir")) {
die ("The directory <b>($upload_dir)</b> doesn't exist");
}
//check if the directory is writable.
if (!is_writeable("$upload_dir")){
die ("The directory <b>($upload_dir)</b> is NOT writable, Please Chmod (777)");
}
//Check first if a file has been selected
//is_uploaded_file('filename') returns true if
//a file was uploaded via HTTP POST. Returns false otherwise.
if (is_uploaded_file($_FILES['filetoupload']['tmp_name']))
{//begin of is_uploaded_file
//Get the Size of the File
$size = $_FILES['filetoupload']['size'];
//Make sure that $size is less than 1MB (1000000 bytes)
if ($size > $size_bytes)
{
echo "File Too Large. File must be <b>$size_bytes</b> bytes.";
exit();
}
//check file type
if (($limit_file_type == "yes") && (!in_array($_FILES['filetoupload']['type'],$allowed_file_type)))
{
echo"wrong file type";
exit();
}
// $filename will hold the value of the file name submetted from the form.
$filename = $_FILES['filetoupload']['name'];
// Check if file is Already EXISTS.
if(file_exists($upload_dir.$filename)){
echo "
<table border='1' style='border-collapse: collapse' bordercolor='#FF0000' bgcolor='#EFEFEF'>
<tr>
<td><font family='Franklin Gothic Book' size='1' color='#FF0000'>$filename already exists on our servers!</font></td>
</tr>
</table>
";
exit();
}
//Move the File to the Directory of your choice
//move_uploaded_file('filename','destination') Moves afile to a new location.
if (move_uploaded_file($_FILES['filetoupload']['tmp_name'],$upload_dir.$filename)) {
//tell the user that the file has been uploaded and make him alink too;).
echo "<img src='$upload_dir$filename'> <br>
Direct link<br>
<input size='60' value='$upload_dir$filename'>";
exit();
}
else
{
//Print error
echo "
<table border='1' style='border-collapse: collapse' bordercolor='#FF0000' bgcolor='#EFEFEF'>
<tr>
<td><font family='Franklin Gothic Book' size='1' color='#FF0000'>There was a problem moving your file</font></td>
</tr>
</table>
";
exit();
}
}//end of is_uploaded_file

?>



Lol you got caught

gutted.

nice find Simon!

Rockstar
04-12-2007, 07:10 PM
whats link to urs Forge

RSTurbo
04-12-2007, 08:26 PM
Seems good,
Thanks very much ;)

Forge
05-12-2007, 05:16 PM
What do you mean link to mine? A demo? :)

Rockstar
05-12-2007, 09:17 PM
What do you mean link to mine? A demo? :)

Yes :D

Forge
05-12-2007, 09:20 PM
Look at the release of the one i made myself! :) theres a demo with that (Forgeload)

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