kencur,sikencur,aplikasi,tips dan trik, informasi,aplikasi sekolah gratis,pendidikan,aplikasi sekolah,bejalar office

PHP get the link after upload data

PHP get the link after upload data. Simple php script to upload data and return back the link of data after we uploaded data. You can copy from this sample code :

<?php
error_reporting(E_ALL & ~E_NOTICE);
if(isset($_POST['submit'])){
      $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https';$host     = $_SERVER['HTTP_HOST'];$script   = $_SERVER['SCRIPT_NAME'];
	  $namascr = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);$url = $protocol . '://' . $host . $script;
	  $jadi = str_replace($namascr,'',$url);
	$uploaddir = './';
	$fileName = $_FILES['userfile']['name'];
	$fileSize = $_FILES['userfile']['size'];
	$tmpName  = $_FILES['userfile']['tmp_name'];
  	$uploadfile = $uploaddir . $fileName;
  if ($fileSize > 0)
  {
  if (move_uploaded_file($tmpName, $uploadfile))
  {
      echo "File = <a href=\"./".$fileName."\">".$fileName."</a> Upload = <b>Success.</b><br />";
	  echo "Link = ".$jadi."".$fileName;
	  echo "<br /><img src=\"".$fileName."\" alt=\"".$fileName."\" width=\"100px\" height=\"100px\" />";
  }
  else
  {
      echo "File = ".$fileName." Upload = <b>Failed.</b><br>";
  }
  }
}
?>

<form name="myform" enctype="multipart/form-data" method="POST">
File: <input name="userfile" type="file"><br>
	<input type="hidden" name="MAX_FILE_SIZE" value="20000000" />
    <input type="submit" name="submit" value="Upload" />
</form>

*Supported in php 4 and 5.

Komentar

Tinggalkan Balasan

Alamat surel Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *