WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Upload any fixed type of files, control file type through javascript and encrypt filename using php so file not get overwrite
Categories : PHP, Java Script, Functions, PHP References, Form Processing Click here to Update Your Picture
Rupali Gulande
Date : Oct 24th 2007
Grade : Be the 1st to grade this Code Example
Viewed : 555
File : 4708.zip
Images : No Images for this code example.
Search : More code by Rupali Gulande
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

In this example we are see how to upload a fixed type of files.
we are going to define a function in javascript and using that function we will going to check extension of file which will get upload.

also encrypt filename using php so file not get overwrite, we are going to add current time span with filename so if one are more file of same name get uploaded will not overwrite each other.

very simple code... see example for details...

<?php
$message
='&nbsp;';
$error=false;
$link=" ";
    if (isset(
$_POST['submit_Tut'])) {
        if (
$_FILES['Tut_thumb']['tmp_name'] !=""){
                       
           
$now_time = date('YmdHis');
           
$tmpName = $_FILES['Tut_thumb']['tmp_name'];
   
           
                     
copy ($_FILES['Tut_thumb']['tmp_name'], "upload/".$now_time.$_FILES['Tut_thumb']['name'])
                        or die (
"Could not copy");
                   
$message="<span style='color:#FF0000;'>File uploaded successfully ...!</span>";
               
$error=true;     
                   
            }
        }
   
   

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>TechXcel</title>
<script type="text/javascript" language="JavaScript">
function vldFrm_Submit_Tut(){
    var result = true;
    var msg="";
       
    if (document.newtut.Tut_thumb.value !=" ") {
        if(document.newtut.Tut_thumb.value.lastIndexOf('.HTML') > -1 ||document.newtut.Tut_thumb.value.lastIndexOf('.html') > -1 ||document.newtut.Tut_thumb.value.lastIndexOf('.php') > -1 ||document.newtut.Tut_thumb.value.lastIndexOf('.PHP') > -1 ||document.newtut.Tut_thumb.value.lastIndexOf('.TXT') > -1 ||document.newtut.Tut_thumb.value.lastIndexOf('.txt') > -1 ||document.newtut.Tut_thumb.value.lastIndexOf('.gif') > -1 || document.newtut.Tut_thumb.value.lastIndexOf('.png') > -1 || document.newtut.Tut_thumb.value.lastIndexOf('.jpg') > -1 || document.newtut.Tut_thumb.value.lastIndexOf('.GIF') > -1|| document.newtut.Tut_thumb.value.lastIndexOf('.PNG') > -1 || document.newtut.Tut_thumb.value.lastIndexOf('.JPG') > -1){
       
        }else{
        msg="HTML, txt, php,jpg, png or gif file can be upload! \n";
        document.newtut.Tut_thumb.focus();
        document.getElementById('Tut_thumb').style.border="1px red solid";
        result = false;
        }
    }
    if(msg==""){
    return result;
    }{
    alert(msg)
    return result;
    }
   
}
</script>
</head>
<body>
<form name="newtut" action="upload.php" method="post" id="commentform" enctype="multipart/form-data" onSubmit="return vldFrm_Submit_Tut();">

<p>
  <label>File Upload... </label>
</p>

<?php
                     
if($error){
                          echo
'<p>'.$message.'</p>';
                    }
?>
<input type="file" name="Tut_thumb" id="Tut_thumb" value="" size="22" tabindex="8">
<label><strong>&nbsp; Select a file </strong></label>
<br>
<input name="submit_Tut" type="submit" id="submit1" tabindex="12" value="Submit" class="button1">
                                    </form>
   
</body>
</html>



PHP and javascript mouseover, mouseout, and mousedown events
Categories : PHP, Java Script, Form Processing, Beginner Guides
showing Help (assistance) to the user while filling html forms.
Categories : HTML, Java Script, Form Processing
This PHP function creates dropdown select lists for time and date that you can change, outputs a 14 char MySQL timestamp in a text field
Categories : PHP, MySQL, Java Script, HTML and PHP
PHP4 session helper HTML file.
Categories : PHP, Java Script, HTML and PHP, Sessions
Visits-tracking
Categories : PHP, Databases, MySQL, Errors and Logging, Functions
Easy alert box pop-up function
Categories : PHP, Java Script, Beginner Guides
Local-to-user date and time display regardless of time zone or where the website's server is located
Categories : PHP, Date Time, HTML and PHP, Java Script
send_mail function to defeat Header Injection Hacking/Spamming
Categories : PHP, Email, Form Processing, Security
Date Validation using JavaScript. Intended to use it as checkdate() from PHP.
Categories : Java Script, Date Time, PHP
Simple Generic Drop Down List Function
Categories : PHP, HTML and PHP, Functions
Classic guest book made with PHP and Flash
Categories : PHP, Flash, Java Script
AJAX Data Grid System using php and mysql. A complete login system with the ability to display data in a grid using ajax. Add , update and delete the records without reloading the page.
Categories : PHP, AJAX, Databases, MySQL, Java Script
The Ajax Tree view class fetches data from a db for the requested parent category id. The data is then stored in an array and converted into JSON (Javascript Object Notation) format. This format is then used by JavaScript for populating tree view.
Categories : PHP, PHP Classes, Java Script, AJAX, Databases
Javascript/DHTML menus without all the extra javascipt.... server side browser detection + dynamically generated javascript (build menus on fly using php)
Categories : PHP, Java Script, Navigation
Popup window creator for images on the Fly.
Categories : PHP, GD image library, Java Script