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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

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

    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
    Code:
    <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 &amp; 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
    Code:
    <?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!!!

    #2
    simple and yet usefull for us a newbie nice share

    Comment


      #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

      Comment


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

        Comment


          #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

          Comment


            #6
            Nice share

            Comment


              #7
              Thanks for share this valuabl script.....

              Comment


                #8
                File to Upload: is ok if if we add File import option is more better. plz some one update and add file import i min url/link upload option

                Comment

                Working...
                X