⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 insert_image.php

📁 灵活强大的会员系统轻松构建互动应用
💻 PHP
字号:
<?php

	error_reporting(0);
	require_once("de_lang/language.php");

	/*//////////////////////////////////////////////////////
	/                                                      /
	/ The $DOCUMENT_ROOT variable is used to specify the   /
	/ location of the image directory. If you are having   /
	/ problems uploading or deleting images, then you      /
	/ will need to change the variable below to the full   /
	/ path to your document root on your web server, such  /
	/ as /htdocs/www/jdoe                                  /
	/                                                      /
	//////////////////////////////////////////////////////*/

	$DOCUMENT_ROOT = @$_SERVER["DOCUMENT_ROOT"];
	$statusText = "";

	// DO NOT MODIFY BELOW THIS LINE
	$validImageTypes = array("image/pjpeg", "image/jpeg", "image/gif", "image/x-png", "image/tiff", "image/tif", "image/bmp", "image/x-MS-bmp");

	// Added for v5.0
	$validImageExts = array("gif","jpg","jpeg","bmp","tiff","tif","png");
	$isValidExt = false;
	
	$ImageDirectory = ereg_replace("/$", "", $_GET["imgDir"]);
	
	// echo $ImageDirectory;

	$URL = $_SERVER["HTTP_HOST"];
	$serverName = $URL;
	$scriptName = dirname($_SERVER["SCRIPT_NAME"]) . "/de/class.devedit.php";
	$HideWebImage = @$_GET["wi"];

	// Workout the location of class.devedit.php
	$url = $_SERVER["SERVER_NAME"];
	$scriptName = "class.devedit.php";
	$scriptDir = strrev(@$_SERVER["PATH_INFO"]);
	$slashPos = strpos($scriptDir, "/");
	$scriptDir = strrev(substr($scriptDir, $slashPos, strlen($scriptDir)));
	$numImages = 0;
	$numInvalid = 0;

	if(@$_GET["imgSrc"] != "")
	{
		// Delete the image
		$imgPath = str_replace("//", "/", $DOCUMENT_ROOT . "/" . $ImageDirectory . "/" . $_GET["imgSrc"]);
		$imgExt = strrev(substr(strrev($imgPath), 0, strpos(strrev($imgPath), ".")));

		// Is this a valid file type?
		if(in_array($imgExt, $validImageExts))
			$isValidExt = true;
		else
			$isValidExt = false;

		if($isValidExt)
		{
			if(@unlink($imgPath))
			{
				// Deleted OK
				$statusText = sTxtImageDeleted;
			}
			else
			{
				// Couldn't delete the imagefile
				$statusText = sTxtCantDelete;
			}
		}
		else
		{
			// Invalid file type
			$statusText = sTxtInvalidImageType;
		}
	}

	if($_GET["ToDo"] == "UploadImage")
	{
		//Data for first file upload
		$newFileName = @$_FILES["upload"]["name"];
		$newFileType = @$_FILES["upload"]["type"];
		$newFileLocation = @$_FILES["upload"]["tmp_name"];
		$newFileSize = @$_FILES["upload"]["size"];

		//Data for second file upload
		$newFileName1 = @$_FILES["upload1"]["name"];
		$newFileType1 = @$_FILES["upload1"]["type"];
		$newFileLocation1 = @$_FILES["upload1"]["tmp_name"];
		$newFileSize1 = @$_FILES["upload1"]["size"];

		//Data for third file upload
		$newFileName2 = @$_FILES["upload2"]["name"];
		$newFileType2 = @$_FILES["upload2"]["type"];
		$newFileLocation2 = @$_FILES["upload2"]["tmp_name"];
		$newFileSize2 = @$_FILES["upload2"]["size"];

		//Data for fourth file upload
		$newFileName3 = @$_FILES["upload3"]["name"];
		$newFileType3 = @$_FILES["upload3"]["type"];
		$newFileLocation3 = @$_FILES["upload3"]["tmp_name"];
		$newFileSize3 = @$_FILES["upload3"]["size"];

		//Data for fifth file upload
		$newFileName4 = @$_FILES["upload4"]["name"];
		$newFileType4 = @$_FILES["upload4"]["type"];
		$newFileLocation4 = @$_FILES["upload4"]["tmp_name"];
		$newFileSize4 = @$_FILES["upload4"]["size"];

		//---------------------------------------------------------
		//Is the first image a valid file type?

		$validFileType = false;
		$errorText = "";

		if($newFileName != "")
		{		
			// Is this file empty?
			if($newFileSize == 0)
				$numInvalid++;
			
			// Is this a valid file type?
			if(in_array($newFileType, $validImageTypes))
				$validFileType = true;
		
			if($validFileType == false)
			{
				// Invalid file type
				$statusText = sTxtImageErr;
			}
			else
			{
				$uploadSuccess = @copy($newFileLocation, $DOCUMENT_ROOT . $ImageDirectory . "/" . $newFileName);

				if($uploadSuccess)
				{
					$statusText = $newFileName . " " . sTxtUploadSuccess . "!";
					$numImages++;
				}
				else
				{
					$statusText = sTxtCantUpload;
				}
			}
		}

		//---------------------------------------------------------
		//Is the second image a valid file type?

		$validFileType = false;
		$errorText = "";

		if($newFileName1 != "")
		{		
			// Is this file empty?
			if($newFileSize1 == 0)
				$numInvalid++;

			// Is this a valid file type?
			if(in_array($newFileType1, $validImageTypes))
				$validFileType = true;
		
			if($validFileType == false)
			{
				// Invalid file type
				$statusText = sTxtImageErr;
			}
			else
			{
				$uploadSuccess = @copy($newFileLocation1, $DOCUMENT_ROOT . $ImageDirectory . "/" . $newFileName1);

				if($uploadSuccess)
				{
					$statusText = $newFileName1 . " " . sTxtUploadSuccess . "!";
					$numImages++;
				}
				else
				{
					$statusText = sTxtCantUpload;
				}
			}
		}

		//---------------------------------------------------------
		//Is the third image a valid file type?

		$validFileType = false;
		$errorText = "";

		if($newFileName2 != "")
		{		
			// Is this file empty?
			if($newFileSize2 == 0)
				$numInvalid++;

			// Is this a valid file type?
			if(in_array($newFileType2, $validImageTypes))
				$validFileType = true;
		
			if($validFileType == false)
			{
				// Invalid file type
				$statusText = sTxtImageErr;
			}
			else
			{
				$uploadSuccess = @copy($newFileLocation2, $DOCUMENT_ROOT . $ImageDirectory . "/" . $newFileName2);

				if($uploadSuccess)
				{
					$statusText = $newFileName2 . " " . sTxtUploadSuccess . "!";
					$numImages++;
				}
				else
				{
					$statusText = sTxtCantUpload;
				}
			}
		}
	
		//---------------------------------------------------------
		//Is the fourth image a valid file type?

		$validFileType = false;
		$errorText = "";

		if($newFileName3 != "")
		{		
			// Is this file empty?
			if($newFileSize3 == 0)
				$numInvalid++;

			// Is this a valid file type?
			if(in_array($newFileType3, $validImageTypes))
				$validFileType = true;
		
			if($validFileType == false)
			{
				// Invalid file type
				$statusText = sTxtImageErr;
			}
			else
			{
				$uploadSuccess = @copy($newFileLocation3, $DOCUMENT_ROOT . $ImageDirectory . "/" . $newFileName3);

				if($uploadSuccess)
				{
					$statusText = $newFileName3 . " " . sTxtUploadSuccess . "!";
					$numImages++;
				}
				else
				{
					$statusText = sTxtCantUpload;
				}
			}
		}
	
		//---------------------------------------------------------
		//Is the fifth image a valid file type?

		$validFileType = false;
		$errorText = "";

		if($newFileName4 != "")
		{		
			// Is this file empty?
			if($newFileSize4 == 0)
				$numInvalid++;

			// Is this a valid file type?
			if(in_array($newFileType4, $validImageTypes))
				$validFileType = true;
		
			if($validFileType == false)
			{
				// Invalid file type
				$statusText = sTxtImageErr;
			}
			else
			{
				$uploadSuccess = @copy($newFileLocation4, $DOCUMENT_ROOT . $ImageDirectory . "/" . $newFileName4);

				if($uploadSuccess)
				{
					$statusText = $newFileName4 . " " . sTxtUploadSuccess . "!";
					$numImages++;
				}
				else
				{
					$statusText = sTxtCantUpload;
				}
			}
		}

		if($numImages > 1)
			$statusText = sTxtImageSuccess;

		if($numInvalid > 0)
			$statusText = sTxtImageErr;
	}
//echo $DOCUMENT_ROOT . $ImageDirectory;
	$dirHandle = @opendir(realpath($DOCUMENT_ROOT . $ImageDirectory)) or die(sTxtImageDirNotConfigured);

	//Get all images into a JavaScript array so that we can workout whether or not
	//uploading an image would overwrite an existing one
	$imageJS = "var imageDir = Array(";

	while(false !== ($file = readdir($dirHandle)))
	{
		$imageJS = $imageJS . "'" . $file . "',";
	}

	//Reload the directory contents
	$dirHandle = @opendir(realpath($DOCUMENT_ROOT . $ImageDirectory)) or die(sTxtImageDirNotConfigured);

	if(substr(strrev($imageJS), 0, 1) == ",")
		$imageJS = substr($imageJS, 0, strlen($imageJS)-1);

	$imageJS = $imageJS . ")";
	$counter = 0;

	?>

		<script language=JavaScript>

		window.onload = this.focus;

		window.opener.doStyles()
		window.onerror = function() { return true; }
		var myPage = window.opener;
		var imageAlign

		<?php echo $imageJS; ?>

		if (window.opener.imageEdit) {
			imageAlign = window.opener.selectedImage.align
		}

		function toggleUploadDiv()
		{
			if(uploadDiv.style.display == "none")
			{
				document.getElementById("toggleButton").value = "銆

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -