• 文件上传PHP


    <?php
    	$targetIp = GetIP();
    	$fileUpload = 'fileUpload';
    	$frameCount = 'frameCount';
    	$fileName = $_FILES[$fileUpload]["name"];
    	$datestr = date("ymdhis");
    	$spanPos = strripos($fileName,".");
    	$sy = substr($fileName,$spanPos);
    	$name = substr($fileName,0,$spanPos);
    	$uploaddir = "D:/xampp/htdocs/upload/files/";
    	$uploadfile = $uploaddir . $name."_".$targetIp.$datestr.$sy;
    	
    	if ($_FILES[$fileUpload]["error"] > 0){
    		echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
        }else{
    		echo "frameCount: ".$_POST[$frameCount]."
    ";
    		echo "Upload: " . $fileName."
    ";
    		echo "Type: " . $_FILES[$fileUpload]["type"]."
    ";
    		echo "Size: " . ($_FILES[$fileUpload]["size"] / 1024)."
    ";
    		echo "Temp file: " . $_FILES[$fileUpload]["tmp_name"]."
    ";
    		if(is_uploaded_file($_FILES[$fileUpload]["tmp_name"])){
    			if (file_exists($uploadfile)){
    				
    				if(unlink($uploadfile)){
    					echo('delete '.$uploadfile.' successful');
    				}else{
    					echo('delete '.$uploadfile.' fail');
    				}
    			}
    			if(move_uploaded_file($_FILES[$fileUpload]["tmp_name"],$uploadfile)){
    				echo 0;
    			}else{
    				echo "Stored in: " . $uploadfile."
    ";
    			}
    		}else{
    			echo 'no uploaded file';
    		}
    	}
    	function GetIP(){
    		if(!empty($_SERVER["HTTP_CLIENT_IP"])){
    			$cip = $_SERVER["HTTP_CLIENT_IP"];
    		}
    		elseif(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
    			$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
    		}
    		elseif(!empty($_SERVER["REMOTE_ADDR"])){
    			$cip = $_SERVER["REMOTE_ADDR"];
    		}
    		else{
    			$cip = "无法获取!";
    		}
    		return $cip;
    	}
    ?>
    

      

    using UnityEngine;
    using System.Collections;
    using System.IO;
    public class TestUploadFiles : MonoBehaviour {
    
    	private string screenShotURL = "http://localhost/upload/uploadlog.php";
    
        // Use this for initialization
        void Start()
        {
        }
    	void OnGUI(){
    		if(GUILayout.Button("UploadPNG")){
    			StartCoroutine(UploadPNG());
    		}
    		if(GUILayout.Button("UploadText")){
    			StartCoroutine(UploadText());
    		}
    		if(GUILayout.Button("UploadFiles")){
    			StartCoroutine(UploadFiles());
    		}
    	}
        IEnumerator UploadPNG()
        {
    
    		yield return new WaitForEndOfFrame();
    		int width = Screen.width;
    		int height = Screen.height;
    		var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
    
    		tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
    		tex.Apply();
    		byte[] bytes = tex.EncodeToPNG();
    		Destroy(tex);
    		WWWForm form = new WWWForm();
    		form.AddField("frameCount", Time.frameCount.ToString());
    		form.AddBinaryData("fileUpload", bytes, "screenShot.txt");
    		WWW w = new WWW(screenShotURL, form);
    		yield return w;
    		if (!string.IsNullOrEmpty(w.error))
    		{
    			print(w.error);
    		}
    		else
    		{
    			print (w.text);
    			print("Finished Uploading Screenshot");
    		}
        }
    	IEnumerator UploadFiles(){
    		string dirPath = "E:\HBWork\HBClient\www.hobbits.dfplay.abtest\log\";
    		string[] filePaths = Directory.GetFiles(dirPath);
    		foreach(string file in filePaths){
    			yield return new WaitForEndOfFrame();
    			FileInfo fileInfo = new FileInfo (file);
    			FileStream fileStream = File.OpenRead (file);
    			byte[] bytes = new byte[fileStream.Length];
    			fileStream.Read (bytes,0,bytes.Length);
    
    			WWWForm form = new WWWForm();
    			form.AddField("frameCount", Time.frameCount.ToString());
    			form.AddBinaryData("fileUpload", bytes, fileInfo.FullName);
    			WWW w = new WWW(screenShotURL, form);
    			yield return w;
    			if (!string.IsNullOrEmpty(w.error))
    			{
    				print(w.error);
    			}
    			else
    			{
    				if (w.text.ToString ().Equals ("0")) {
    					print ("Successful");
    				}
    			}
    		}
    	}
    	IEnumerator UploadText()
    	{
    		string logPath = "E:\HBWork\HBClient\www.hobbits.dfplay.abtest\log\log_0.bak1.txt";
    		FileStream fileStream = File.OpenRead (logPath);
    		byte[] bytes = new byte[fileStream.Length];
    		fileStream.Read (bytes,0,bytes.Length);
    
    		WWWForm form = new WWWForm();
    		form.AddField("frameCount", Time.frameCount.ToString());
    		form.AddBinaryData("fileUpload", bytes, "log_0.bak1.txt", "image/png");
    		WWW w = new WWW(screenShotURL, form);
    		yield return w;
    		if (!string.IsNullOrEmpty(w.error))
    		{
    			print(w.error);
    		}
    		else
    		{
    			print (w.text);
    			print("Finished Uploading Screenshot");
    		}
    
    	}
    }
    

    参考:http://php.net/manual/zh/

  • 相关阅读:
    [Oracle] CPU/PSU补丁安装详细教程
    weblogic 升级bsu_Weblogic补丁升级之坑坑洼洼
    weblogic补丁下载与安装补丁的方法
    weblogic补丁安装失败
    【项目】项目56
    【项目】项目55
    【项目】项目54
    【项目】项目53
    【项目】项目52
    【项目】项目51
  • 原文地址:https://www.cnblogs.com/mttnor/p/6141691.html
Copyright © 2020-2023  润新知