Jump to content

Simple uploading system

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
19 replies to this topic

#1
Guest_Jaan_*

Guest_Jaan_*
  • Guests

Posted Image

Attached Files


Edited by Jaan, 08 June 2010 - 09:31 AM.


#2
Guest_eikukaan_*

Guest_eikukaan_*
  • Guests
Awesome!

#3
Chewie

Chewie

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,579 posts
Good stuff Jaan!

#!CrunchBang Linux ~$ apt-get into it | #!(Statler:R20101205): OpenBox | Like Linux?
“The cure for boredom is curiosity. There is no cure for curiosity.”


#4
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Hmm, for some reason it didn't work for me. Even after I made the upload folder, in the same folder as the upload.php file. :confused:

None the less, I did get it to work, after changing it a bit. :D

#5
Guest_Jaan_*

Guest_Jaan_*
  • Guests
What was wrong?

#6
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
I have no idea but I changed it to:


<?php


//This function will display your form

function form(){


echo "<form action='upload.php' enctype='multipart/form-data' method='post'>"

	."Select your file for upload: <input type='file' name='file' size='30'> "

	."<input type='submit' value='Upload' name='submit'>";


}


//This function will upload your file

function upload(){


//Let's collect all info into variables

$file = $_FILES['file']['name'];

$type = $_FILES['file']['type'];

$size = $_FILES['file']['size'];

$temp = $_FILES["file"]["tmp_name"];


//Let's set max file size to 2mb

$max_size = "2097152";


//Now set allowed file types

$allow_type_1 = "image/jpeg";

$allow_type_2 = "image/gif";

$allow_type_3 = "image/png";

$allow_type_4 = "image/bmp";



//If file size is bigger than 2mb than let's display an error

if($size > 2097152){

die("File is to big!");

}



//Now file type check, if file is not right we will display an error

if($type == $allow_type_1 or $type == $allow_type_2 or $type == $allow_type_3 or $type == $allow_type_4){


//If everything is good then let's upload


move_uploaded_file($temp, "upload/$file");

echo "Download: <a href='upload/$file'>Download $file</a>";


}else{


echo "Wrong file!";


}



}


if (empty($_POST['submit'])) {

form();

} else {

upload();

}

?>


and it worked :D Good work on tutorial BTW :D

#7
Guest_Jaan_*

Guest_Jaan_*
  • Guests
lol nice change.. thanks anyway :D

#8
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
I don't know why, the one you had wasn't working. When I click "upload" all it did was refresh the page. :(

I'd give you some +rep, if I could but I gave you some recently. :D

#9
Guest_Jaan_*

Guest_Jaan_*
  • Guests
lol.. i don't know.. all my scripts work for me.. so i don't know what's wrong :/

#10
Chewie

Chewie

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,579 posts
Its over their heads Jaan..

#!CrunchBang Linux ~$ apt-get into it | #!(Statler:R20101205): OpenBox | Like Linux?
“The cure for boredom is curiosity. There is no cure for curiosity.”


#11
Guest_Jaan_*

Guest_Jaan_*
  • Guests

XaNaX said:

Its over their heads Jaan..

what do you mean?

#12
Chewie

Chewie

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,579 posts
Its a term, meaning there too inferior to use it lol was what i was inferring i was being an as*! =p sorry boys.

#!CrunchBang Linux ~$ apt-get into it | #!(Statler:R20101205): OpenBox | Like Linux?
“The cure for boredom is curiosity. There is no cure for curiosity.”