Jump to content

How to submit a file through a php forum..?


milan
 Share

Recommended Posts

Use This.

<?PHP//------------Config----------------define('upload_allowfiletype','tif,gif,png,jpg,jpeg,doc,docx,xls,xlsx,ppt,pptx,jpg,pdf,zip,rar,txt');define('allowfilesize',3);//Maximum File Size (Mb);define('uploadfolder','upload/');//Upload Folderdefine('rename_on_upload',true);//Random and rename file While Upload//----------------------------------?><form name="upload file" method="post"  enctype="multipart/form-data" action=""><br/>File: <input type="file" name="file1"><br/><input type="submit" value="Start Upload" name="submit"></form><?PHPif (isset($_POST['submit'])){createfolder(uploadfolder);$uploadedfilename=upload('file1');/*$checkerror=explode(":",$uploadedfilename);if ($checkerror[0]<>'error'){  //store $uploadedfilename in database;}*/}echo '<br/>----------------------------------<br/>'; //------------Function----------------function upload($file){$allowedExts=explode(",",upload_allowfiletype); $filetype = explode(".", $_FILES[$file]["name"]);$filetype = end($filetype);if (($_FILES[$file]["type"] == "image/gif"|| $_FILES[$file]["type"] == "image/jpeg"|| $_FILES[$file]["type"] == "image/pjpeg")&& $_FILES[$file]["size"] < (allowfilesize*1024*1024)&& in_array($filetype, $allowedExts)){if ($_FILES[$file]["error"] > 0){  echo "Return Code: " . $_FILES[$file]["error"] . "<br />";  return 'error: '.$_FILES[$file]["error"];}else{echo "Upload: " . $_FILES[$file]["name"] . "<br />";echo "Type: " . $_FILES[$file]["type"] . "<br />";echo "Size: " . ($_FILES[$file]["size"] / 1024) . " Kb<br />";echo "Temp file: " . $_FILES[$file]["tmp_name"] . "<br />";}if (file_exists(uploadfolder."/" . $_FILES[$file]["name"])){  echo '<span style=" color:#00F;"> '.$_FILES[$file]["name"].'</span>' . '<span style=" color:#F00;">Already exists. </span>';  return 'error: File Already exists';}else{  if (rename_on_upload==TRUE)	{		  //$filenewcon = strstr($_FILES[$file]["tmp_name"],'.');		  $now = date("Ymd"); //date("Dgis");		  $passw = rand()*7;		  $random_file_name=$now."-".$passw; //$random_file_name="$now$passw$filenewcon";		  move_uploaded_file( $_FILES[$file]["tmp_name"],uploadfolder.'/'.$random_file_name.'.'.$filetype);		  echo '<span style=" color:#00F;">Stored in: ' .uploadfolder.'/'. $random_file_name.'</span><br/><br/>';		  return $random_file_name;	}	else	{		  //----------------------------------------------------------------------------------------------------		  move_uploaded_file($_FILES[$file]["tmp_name"],uploadfolder.'/'.$_FILES[$file]["name"]);		  //echo "Stored in: " .uploadfolder.'/'. $_FILES[$file]["name"]."<br/><br/>";		  echo '<span style=" color:#00F;">Stored in: <a href="'.uploadfolder.'">' .uploadfolder.'</a>'.$_FILES[$file]["name"].'</span>';		  return $_FILES[$file]["name"];	}}}else{  echo '<div style=" color:#F00;">Invalid file</div>';  return 'error: Invalid file';}}function createfolder($foldername){//$foldername='FolderName';if(!file_exists($foldername)){$flgCreate = mkdir($foldername,"0777");if($flgCreate){  echo 'Folder <a href="'.$foldername.'">$foldername</a> Created.';}else{  echo 'Folder <a href="'.$foldername.'">$foldername</a> Not Create.<br/>  Please Create Folder '.$foldername.' and Cmod to 777 By Your Self';}}else{// echo 'Folder <a href="'.$foldername.'">$foldername</a> Already Created';}}

Edited by kanchatchai
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...