|
|
|
|
|
|
| |
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=' ';
$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> 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 | |
|
|
|