[php tut] simple upload script (supports saving file with select option)

Started on the old forum in October 2012 · view the original in the archive · old links redirect here

7 replies · 933 views · started 14 years ago · 1 min read

7 participants
James John Newbie · 5 posts #1

THIS TUTORIAL WILL LEAD YOU THROUGH IN FILE UPLOADING AND SAVING FILE FROM THE OPTION SELECTED

NOW CREATE YOU WILL CREATE TWO PAGE 1. Upload.php - where you will upload the file 2. Upload2.php - Where the php code will be executed

NOW COPY THIS AND PASTE IN THE upload.php

<form enctype="multipart/form-data" method="post" action="upload2.php">
            <label for="file"><strong>File to Upload:</strong></label>
            <br />
            <input id="file" type="file" name="file" /><br />
            <br />
            <strong>File Category (please select correctly other wise may not be uploaded)<br />
            </strong>
            <select name="option">
              <option selected="selected">
                Java Games              </option>
              
              <option>
                Java Applications              </option>
              
              <option>
                Symbian Applications              </option>
              
              <option>
                Symbian Games              </option>
              
              <option>
                Mobile Themes              </option>
              
              <option>
                PC Softwares              </option>
              
              <option> Musics & Ringtones </option>
              
              <option>
                Zip files, site scripts, prov files and others              </option>
            </select>
       
            <br />
            <input name="Upload" type="submit" class="style1" value="Upload" />
          </form>

THEN SAVE TO YOUR CPANEL AND CREATE ANOTHER FILE upload2.php AND PASTE THIS....BEFORE THAT CREATE A FOLDER WHERE THE FILES WILL BE SAVED

1. Uploads and inside uploads create java_games, java_apps, symbian_apps, symbian_games, pc, themes, pictures, video, musics, zip

NOW COPY THIS INTO THE upload2.php

<?php 
//this script originated from 2netlodge, please don't remove

//assigning directories to variable
$jgames = 'uploads/java_games';
$japps = 'uploads/java_apps';
$sapps = 'uploads/symbian_apps';
$sgames = 'uploads/symbian_games';
$pc = 'uploads/pc';
$themes = 'uploads/themes';
$pictures = 'uploads/pictures';
$video = 'uploads/video';
$music = 'uploads/musics';
$zip = 'uploads/zip';

//checking file size before upload
if(($_FILES['file']['size']<2000000000))
{
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Error: " . $_FILES["file"]["error"] . "<br />";
    }
else
	{
echo "<div class='me'><div id='even'><center><b>File Successfully Uploaded!</b></center>
<div class='rmenu'><b>FILE DETAILS: </b></div>
<hr><b>File Name:</b> " . $_FILES["file"]["name"] . "</hr>";
    echo "<hr><b>File Type:</b> " . $_FILES["file"]["type"] . "</hr>";
    echo "<hr><b>Size: </b>" . ($_FILES["file"]["size"] / 1000) . " Kb</hr>";
	echo "<hr><b>Comment: </b>" . $_POST['comment'] . "</hr>";
	echo "<hr><b>File Category:</b> " . $_POST['option'] . "</hr><br/>";
	}
//moving uploaded file to folder depending on the chosen option in upload.php
if($_POST["option"]=="Java Games")
	 { 
	   move_uploaded_file($_FILES["file"]["tmp_name"], "$jgames" . $_FILES["file"]["name"]); 
	 }
elseif($_POST["option"]=="Java Applications")
	 { 
	   move_uploaded_file($_FILES["file"]["tmp_name"], "$japps" . $_FILES["file"]["name"]); 
	 }
elseif($_POST["option"]=="Symbian Applications")
	 { 
	   move_uploaded_file($_FILES["file"]["tmp_name"], "$sapps" . $_FILES["file"]["name"]); 
	 }
elseif($_POST["option"]=="Symbian Games")
	 { 
	   move_uploaded_file($_FILES["file"]["tmp_name"], "$sgames" . $_FILES["file"]["name"]); 
	 }
elseif($_POST["option"]=="Mobile Themes")
	 { 
	   move_uploaded_file($_FILES["file"]["tmp_name"], "$themes" . $_FILES["file"]["name"]); 
	 }
elseif($_POST["option"]=="PC Softwares")
	 { 
	   move_uploaded_file($_FILES["file"]["tmp_name"], "$pc" . $_FILES["file"]["name"]); 
	 }
elseif($_POST["option"]=="Musics & Ringtones")
         {
            move_uploaded_file($_FILES["file"]["tmp_name"], "$music" . $_FILES["file"]["name"]); 
          }
elseif($_POST["option"]=="Zip files, site scripts, prov files and others")
{
            move_uploaded_file($_FILES["file"]["tmp_name"], "$zip" . $_FILES["file"]["name"]); 
          }
//if no category not selected 
else 
	{
		echo "Sorry no category supports the file type";
	}
}
else
echo 'Error Uploading file, try again, check your file size</div></div>';
?>

THEN UPLOAD TO YOUR CPANEL ENJOY!!!

hi_jakkk Developer · 52 posts #2

simple and yet usefull for us a newbie 🙂 nice share

softwarefreak Senior · 349 posts #3

THEN UPLOAD TO YOUR CPANEL ENJOY!!!

Yeah awesome, but the problem is, the cpanel won't be there to enjoy by the person using this script.

I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID

James John Newbie · 5 posts #4

ya am still a newbie....jst trying ma best

shushant Developer · 207 posts #5

i will suggest to add some security fix in your code and instead of comparing with mime type and file associations just check its hex signature

Shojol80 Newbie · 1 posts #7

Thanks for share this valuabl script.....

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close