TNW provides the best ICT solutions for your business by the reasonable price.

Recently Developed Websites

1 / 4
amogtech
2 / 4
mhk
3 / 4
apzm
4 / 4
ccg


We can set the limitations in uploading files. For example, we allow to upload only jpg or jpeg images and the maximum file size is 800KB.

 

<?php
@$name = $_FILES['file']['name'];
@$type = $_FILES['file']['type'];
@$size = $_FILES['file']['size'];

@$extension = substr($name, strpos($name, '.')+1);
@$max_size = 800000;

@$tmp_name = $_FILES['file']['tmp_name'];
@$location = 'tnw87/';


if(isset($name) && !empty($name)){
if($extension == 'jpg' || $extension == 'jpeg'){
 if($size < $max_size){
 if(move_uploaded_file($tmp_name, $location.$name)){
  echo 'Successfully uploaded!';
 }else{
  echo 'Upload Errors!';
 }
 }else{
  echo 'The maximum file size is 800KB';
 }
}else{
 echo 'Only jpg or jpeg image is allowed!';
}
}else{
 echo 'Please choose a file to upload';
}

?>

<form action = "upload.php" method = "POST" enctype = "multipart/form-data">
<input type = "file" name="file"><br /><br />
<input type = "submit" value = "Submit">
</form>


Share On:

In this example, we will upload file to the designated location. So, we will create a folder to store the files we've uploaded and give name to that folder. I give it as tnw87. Ok, lets start write the following codes and discover how it works.

<?php

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

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

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

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


 if(@isset($name) && @!empty($name)){

 $location = 'tnw87/';

 
 if(move_uploaded_file($tmp_name, $location.$name)){

  echo $name. ' is successfully uploaded.';

 }else{

  echo 'Upload Errors';

 }

 }else{

  echo 'Please select file to upload';

 }

 ?>

 <style type = "text/css">

 form{margin-top : 100px; margin-left : 50px;}

 </style>

 <form action = "upload.php" method = "POST" enctype = "multipart/form-data">

 <input type = "file" name = "file"></br></br>

 <input type = "submit" value = "Upload">

 </form>


Share On:

When we upload a file into one location, the file is firstly saved in temporary location as a temp file. Ok, lets discover how it works. We will write the following codes and test it.

 

<?php

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

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

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

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

 
 if(@isset($name) && @!empty($name)){

 $location = 'tnw87/';


 if(move_uploaded_file($tmp_name, $location.$name)){

  echo $name. ' is successfully uploaded.';

 }else{

  echo 'Upload Errors';

 }
 

 }else{

  echo 'Please select file to upload';

 }

 ?>

 <style type = "text/css">

 form{margin-top : 100px; margin-left : 50px;}

 </style>

 <form action = "upload.php" method = "POST" enctype = "multipart/form-data">

 <input type = "file" name = "file"></br></br>

 <input type = "submit" value = "Upload">

 </form>


Share On:

<?php

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

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

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


 if(@isset($name) && @!empty($name)){

  echo 'File name is <strong> '.$name.'</strong>, File type is <strong>'.$type.'</strong> nad File size is <strong> '.$size.'</strong>';

 }else{

  echo 'Please select file to upload';

 }

 ?>

 <style type = "text/css">

 form{margin-top : 100px; margin-left : 50px;}

 </style>

 <form action = "upload.php" method = "POST" enctype = "multipart/form-data">

 <input type = "file" name = "file"></br></br>

 <input type = "submit" value = "Upload">

 </form>


Share On:

<?php

$time = time();
$time_now = date('D M Y & H:i:s', $time);
$time_modified = date ('D M Y @ H:i:s', strtotime('+ 1 year') );

echo 'The current time is '.$time_now.'.</br>The time modified is '.$time_modified.'.'  ;

?>


Share On:

<?php

$redirect_page = 'https://www.tnw87.com';
$redirect = true;

if($redirect == true){
  header('location:' .$redirect_page);
}

?>


Share On:

<?php


$offset = 0;

if(isset($_POST['text']) && isset($_POST['search']) && isset($_POST['replace'])){
 $text = $_POST['text'];
 $search = $_POST['search'];
 $replace = $_POST['replace'];


 $search_length = strlen($search);
 
 if(!empty($text) && !empty($search) && !empty($replace)){
   while($strpos = strpos($text, $search, $offset)){
   $offset = $strpos + $search_length;
   $text = substr_replace($text, $replace, $strpos, $search_length);
   echo $text;
   }
 }else{
   echo 'Please fill all fields!';
 }
}
?>

<hr />
<form action="searchandreplace.php" method="POST">
<textarea name="text" rows="15" cols="60"></textarea><br /><br />
Search : </br>
<input type="text" name="search"><br /><br />
Replace : </br>
<input type="text" name="replace"><br /><br />
<input type="submit" value="Submit">
</form>


Share On: