zoukankan      html  css  js  c++  java
  • 文件上传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/

  • 相关阅读:
    flex+java+blazeds 多通道好文
    如何保持PC客户端一直处于登录状态
    函数进阶
    数据类型扩展
    python编码规范
    xpath轴定位
    IDEA Terminal 运行mvn命令报该命令不是内部命令
    java环境安装Firefox驱动/IE驱动
    java环境添加chrome驱动
    java安装selenium webdriver环境
  • 原文地址:https://www.cnblogs.com/mttnor/p/6141691.html
Copyright © 2011-2022 走看看