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/

  • 相关阅读:
    浏览器内核
    手机端开发适配问题
    关于样式的问题
    nginx和uwsgi的区别和作用
    Flask (七) 部署
    Flask (六) 项目(淘票票)
    Flask (五) RESTful API
    Flask (四) 模型进阶
    Flask (三) 数据迁移
    Flask (二) cookie 与 session 模型
  • 原文地址:https://www.cnblogs.com/mttnor/p/6141691.html
Copyright © 2011-2022 走看看