Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
Alex Makhov  
#1 Posted : Thursday, October 19, 2006 5:51:36 PM(UTC)
Alex Makhov

Rank: Advanced Member

Groups: Member
Joined: 8/3/2003(UTC)
Posts: 998

Dear visitors,

Here are few server scripts for different platforms that could be used to test Image Uploader settings. Each of these scripts saves all the successfully uploaded files to the folder named './Dumps/' by default. Make sure you have set all the appropriate permissions to write files to correctly.

How to use it:
  1. Download appropriate ExtractFiles script. Put it along with your upload script.
  2. Point the url to Extract Files script in Action property instead of url to upload script. For example:
    Code:
    iu.addParam("Action", "ExtractFiles.aspx");
  3. In folder where you put ExtractFiles script create Dumps subfolder. Do not forget to set write permissions for for this folder.
  4. Try to upload files using Image Uploader. In Dumps folder you will find .txt file which contains POST-request fields.

Edited by moderator Tuesday, February 12, 2013 1:16:01 AM(UTC)  | Reason: Not specified

File Attachment(s):
ExtractFiles.aspx.zip (1kb) downloaded 545 time(s).
ExtractFiles.asp.zip (1kb) downloaded 478 time(s).
ExtractFiles_OnlyDump.asp.zip (1kb) downloaded 424 time(s).
ExtractFiles.php.zip (2kb) downloaded 52 time(s).
Sincerely yours,
Alex Makhov

UserPostedImage Follow Aurigma on Twitter!
Alex Makhov  
#2 Posted : Monday, December 11, 2006 6:53:09 PM(UTC)
Alex Makhov

Rank: Advanced Member

Groups: Member
Joined: 8/3/2003(UTC)
Posts: 998

Hello,

Here is the ASP.NET version of SelectFolder sample.

Here is sample folder structure:
Code:
SelectFolder
	\default.aspx
	\gallery.aspx
	\iuembed.js
	\style.css
	\upload.aspx
	\Gallery
		\Folder1
		\Folder2
			\Subfolder1
				\Deepfolder1
				\Deepfolder2		
			\Subfolder2
		\Folder3
		\Folder4
		\Folder5

Here is the screenshot of the sample:

UserPostedImage

Source files are available in this message attachment.

Edited by user Monday, December 21, 2009 2:32:30 AM(UTC)  | Reason: Not specified

File Attachment(s):
default.aspx (4kb) downloaded 393 time(s).
upload.aspx (4kb) downloaded 357 time(s).
style.css (1kb) downloaded 356 time(s).
upload.aspx (4kb) downloaded 308 time(s).
Alex Makhov attached the following image(s):
Scr2.JPG
Sincerely yours,
Alex Makhov

UserPostedImage Follow Aurigma on Twitter!
Alex Makhov  
#3 Posted : Thursday, February 15, 2007 8:30:39 PM(UTC)
Alex Makhov

Rank: Advanced Member

Groups: Member
Joined: 8/3/2003(UTC)
Posts: 998

Hello,

Here is the code of the files from this topic:

ExtractFiles.aspx
Code:
<%@ Page Language="vb" autoeventwireup="false" Debug="true" %>
<%@ Import Namespace="System.IO" %>
<%--
'*********************************************************************************
' Aurigma Image Uploader for ActiveX 4.0 Sample Script
' Aurigma Image Uploader for Java 2.0 Sample Script
' Copyright(c) Aurigma Inc. 2002-2007
' WWW: http://www.aurigma.com
'*********************************************************************************
--%>
<script runat="server">

Dim strPathToSave As String = "./Dumps/"

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   
	    strPathToSave = strPathToSave + Request.Form("PackageGuid")
		
            If (Request.Form("PackageIndex") is nothing) Then
		strPathToSave = strPathToSave + "/"		
	    Else
		strPathToSave = strPathToSave + "_" + Request.Form("PackageIndex") + "/"
	    End If

            'Delete source images
            Dim MyFileInfo As FileInfo
            Dim MyDirectory As DirectoryInfo
            MyDirectory = New DirectoryInfo(Server.MapPath(strPathToSave))
	    MyDirectory.Create()
            For Each MyFileInfo In MyDirectory.GetFiles
                MyFileInfo.Delete
            Next
   
            Dim I As Integer, PostFile As HttpPostedFile
            For I=0 To Request.Files.Count-1
		PostFile = Request.Files(I)
                PostFile.SaveAs (Server.MapPath(strPathToSave & Path.GetFileName(PostFile.FileName)))'PostFile.FileName))
            Next

	    Request.SaveAs(Server.MapPath(strPathToSave + "ExtractDump.txt"),true)		
    End Sub
</script>

ExtractFiles.asp
Code:
<%@ Language="JScript" %>
<%
// *********************************************************************************
// Aurigma Image Uploader for ActiveX 4.0 Sample Script
// Aurigma Image Uploader for Java 2.0 Sample Script
// Copyright(c) Aurigma Inc. 2002-2007
// WWW: http://www.aurigma.com
// *********************************************************************************
%>
<%

// Path and filenames
var UploadFolder = "./Dumps/";
var RequestDump = "ExtractDump.txt";

// Extracting type, only one method can be used.
var SaveBinaryDump = Request.QueryString("ExtractMethod") == "Binary";

// Creating upload folder or deleting files in it.
var fso = Server.CreateObject("Scripting.FileSystemObject");

if (!fso.FolderExists(Server.MapPath(UploadFolder)))
{
	fso.CreateFolder(Server.MapPath(UploadFolder));
} else
{
	var objFolder = fso.GetFolder(Server.MapPath(UploadFolder));
	var objFilesEnum = new Enumerator(objFolder.files);
	for (; !objFilesEnum.atEnd(); objFilesEnum.moveNext())
	{
		fso.DeleteFile(objFilesEnum.item(), true);
	}
}

if (SaveBinaryDump)
{
	// Saving dump to file
	var objAdoStream = Server.CreateObject("ADODB.Stream");
	var adSaveCreateOverwrite = 2;
	objAdoStream.Open();
	objAdoStream.Type = 1;
	objAdoStream.Write(Request.BinaryRead(Request.TotalBytes));
	objAdoStream.SaveToFile(Server.MapPath(UploadFolder) + "/" + RequestDump, adSaveCreateOverwrite);
	objAdoStream.Close();
} else
{
	// Creating objects
	var objUpload = Server.CreateObject("Dundas.Upload.2");
	objUpload.UseUniqueNames = false;
	var objSourceFile = objUpload.GetNextFile();
	while (objSourceFile != null)
	{
		objSourceFile.Save(Server.MapPath(UploadFolder));
		objSourceFile = objUpload.GetNextFile();	
	}
}
%>

ExtractFiles.php
Code:
<?php
/*********************************************************************************
 Aurigma Image Uploader for ActiveX 4.0 Sample Script
 Aurigma Image Uploader for Java 2.0 Sample Script
 Copyright(c) Aurigma Inc. 2002-2007
 WWW: http://www.aurigma.com
*********************************************************************************/

	// Set to "0" the value below to do not create additional directory with package GUID name:
	$createGUIDDirectory = 1;

	// Set directory name to save uploaded files at:
	$relativePathToSave = "Dumps";
	
	// Get the uploaded files count:
	$fileCount = $_POST["FileCount"];
	
	// Value to store correct path:
	$correctPath = $relativePathToSave . "/";
	
	// Get the package GUID:
	$packageGUID = $_POST["PackageGuid"];
	
	// Create directories to save uploaded files:
	if (!is_dir($relativePathToSave))
	{
		mkdir($relativePathToSave);
	}
	if ($createGUIDDirectory == 1)
	{
		if (!is_dir($relativePathToSave . "/" . $packageGUID))
		{
			mkdir($relativePathToSave . "/" . $packageGUID);
		}
		$correctPath = $correctPath . $packageGUID . "/";
	}
	
	// Save dump to file: ExtractDump.txt
//	$filePtr = fopen($correctPath . "ExtractDump.txt", "w+");
//	fwrite($filePtr, $_POST);
//	fclose($filePtr);
	
	// Main cycle:
	for ($i = 1; $i <= $fileCount; $i++)
	{
		$sourceFileField = "SourceFile_" . $i;
		if ($_FILES[$sourceFileField]["size"])
		{
			$fileName = $_FILES[$sourceFileField]["name"];
			move_uploaded_file($_FILES[$sourceFileField]["tmp_name"], $correctPath . $fileName);
		}

		$thumbnail1Field = "Thumbnail1_" . $i;
		if ($_FILES[$thumbnail1Field]["size"])
		{
			if (!is_dir($correctPath . "Thumbnail1"))
			{
				mkdir($correctPath . "Thumbnail1" . "/");
			}
			move_uploaded_file($_FILES[$thumbnail1Field]["tmp_name"], $correctPath . "Thumbnail1/" . $fileName . ".jpg");
		}
		
		$thumbnail2Field = "Thumbnail2_" . $i;
		if ($_FILES[$thumbnail2Field]["size"])
		{
			if (!is_dir($correctPath . "Thumbnail2"))
			{
				mkdir($correctPath . "Thumbnail2" . "/");
			}
			move_uploaded_file($_FILES[$thumbnail2Field]["tmp_name"], $correctPath . "Thumbnail2/" . $fileName . ".jpg");
		}
		
		$thumbnail3Field = "Thumbnail3_" . $i;
		if ($_FILES[$thumbnail3Field]["size"])
		{
			if (!is_dir($correctPath . "Thumbnail3"))
			{
				mkdir($correctPath . "Thumbnail3" . "/");
			}
			move_uploaded_file($_FILES[$thumbnail3Field]["tmp_name"], $correctPath . "Thumbnail3/" . $fileName . ".jpg");
		}
	}
?>

ExtractFiles_OnlyDump.asp
Code:
<%@ Language="JScript" %>
<%
//*********************************************************************************
// Aurigma Image Uploader for ActiveX 4.0 Sample Script
// Aurigma Image Uploader for Java 2.0 Sample Script
// Copyright(c) Aurigma Inc. 2002-2007
// WWW: http://www.aurigma.com
//*********************************************************************************
%>
<%

// Path and filenames
var UploadFolder = "./Dumps/";
var RequestDump = "ExtractDump.txt";

// Creating upload folder or deleting files in it.
var fso = Server.CreateObject("Scripting.FileSystemObject");

if (!fso.FolderExists(Server.MapPath(UploadFolder)))
{
	fso.CreateFolder(Server.MapPath(UploadFolder));
} else
{
	var objFolder = fso.GetFolder(Server.MapPath(UploadFolder));
	var objFilesEnum = new Enumerator(objFolder.files);
	for (; !objFilesEnum.atEnd(); objFilesEnum.moveNext())
	{
		fso.DeleteFile(objFilesEnum.item(), true);
	}
}

// Saving dump to file
var objAdoStream = Server.CreateObject("ADODB.Stream");
var adSaveCreateOverwrite = 2;
objAdoStream.Open();
objAdoStream.Type = 1;
objAdoStream.Write(Request.BinaryRead(Request.TotalBytes));
objAdoStream.SaveToFile(Server.MapPath(UploadFolder) + "/" + RequestDump, adSaveCreateOverwrite);
objAdoStream.Close();
%>

Edited by user Thursday, May 22, 2008 7:12:47 PM(UTC)  | Reason: Not specified

Sincerely yours,
Alex Makhov

UserPostedImage Follow Aurigma on Twitter!
Alex Makhov  
#4 Posted : Monday, February 19, 2007 8:41:58 PM(UTC)
Alex Makhov

Rank: Advanced Member

Groups: Member
Joined: 8/3/2003(UTC)
Posts: 998

Here is changed Multiple Descriptions Sample code which allows several package file upload processing. The original sample does not support FilesPerOnePackageCount property usage so we have made a code sample which does. Here it is:

default.aspx
Code:
<%@ Page Language="C#" AutoEventWireup="false" %>
<!--BEGIN-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Aurigma Image Uploader</title>

	<script src="../iuembed.js" type="text/javascript"></script>

	<script src="script.js" type="text/javascript"></script>

	<link href="style.css" type="text/css" rel="stylesheet" />
</head>
<body>
	


		This demo application shows to create custom upload pane through HTML code. This
		custom pane allows to associate additional data with each data - file title and
		description. It can be easily modified to send any other data. In addition, it demonstrates
		how to:
	
	<ul>
		<li>Create custom HTML buttons for Image Uploader instead of standard ones.</li>
		<li>Upload thumbnail along with a source file.</li>
	</ul>
	<fieldset>
		<legend>Note</legend>This demo application <strong>deletes all previously uploaded files</strong>.
		Keep in mind that it is a feature of this demo, not of Image Uploader itself. If
		you <strong>do not want to delete uploaded files</strong>, you should modify the
		upload processing page specified by the <strong>Action</strong> parameter.
	</fieldset>
	<table>
		<tbody>
			<tr>
				<td align="right">
					<input id="UploadButton" type="button" value="Upload Files" disabled="disabled" onclick="UploadButton_click();" />
				</td>
			</tr>
			<tr>
				<td>

					<script type="text/javascript">
//Create JavaScript object that will embed Image Uploader to the page.
var iu = new ImageUploaderWriter("ImageUploader1", 650, 250);

//For ActiveX control full path to CAB file (including file name) should be specified.
iu.activeXControlCodeBase = "../ImageUploader4.cab";
iu.activeXControlVersion = "4,1,21,0";

//For Java applet only path to directory with JAR files should be specified (without file name).
iu.javaAppletCodeBase = "../";
iu.javaAppletCached = true;
iu.javaAppletVersion = "2.1.21.0";

//iu.showNonemptyResponse = "off";

//Configure appearance.
iu.addParam("PaneLayout", "ThreePanes");
iu.addParam("FolderView", "Thumbnails");

[b]iu.addParam("FilesPerOnePackageCount", "3");[/b]

iu.addParam("BackgroundColor", "#eff1f9");
iu.addParam("ShowUploadListButtons", "true");
iu.addParam("ButtonRemoveFromUploadListText", "");
iu.addParam("ButtonRemoveAllFromUploadListText", "");

iu.addParam("ShowDescriptions", "false");
iu.addParam("EnableRotate", "false");
iu.addParam("ShowButtons", "false");

//Hide standard upload pane.
iu.addParam("FolderPaneHeight", "-1");

//Configure thumbnail settings.
iu.addParam("UploadThumbnail1FitMode", "Fit");
iu.addParam("UploadThumbnail1Width", "120");
iu.addParam("UploadThumbnail1Height", "120");
iu.addParam("UploadThumbnail1JpegQuality", "60");

iu.addParam("ShowDebugWindow", "True");

//Configure URL files are uploaded to.
iu.addParam("Action", "upload.aspx");

//Configure URL where to redirect after upload.
iu.addParam("RedirectUrl", "gallery.aspx");

//Add event handlers.
iu.addEventListener("UploadFileCountChange", "ImageUploader_UploadFileCountChange");
iu.addEventListener("BeforeUpload", "ImageUploader_BeforeUpload")
iu.fullPageLoadListenerName = "fullPageLoad";

//Tell Image Uploader writer object to generate all necessary HTML code to embed 
//Image Uploader to the page.
iu.writeHtml();
					</script>

				</td>
			</tr>
			<tr>
				<td>
				<!--
				        The code which forms the upload pane itself is located in a separate script.js file.
				        It is highly recommended to keep this code in a separate file to avoid problems with 
				        Internet Explorer with security update 912945 (ActiveX controls activation):
				        
				        http://support.microsoft.com/kb/912945/en-us 
				-->
					<div id="UploadPaneFrame">
						<div id="UploadPane"></div>
					</div>
				</td>
			</tr>
		</tbody>
	</table>
</body>
</html>
<!--END-->

script.js
Code:
var imageUploader1 = null;
var uniqueId = 0;
var prevUploadFileCount = 0;
var dragAndDropEnabled = true;


var allowDrag = false;

function fullPageLoad(){
	imageUploader1 = getImageUploader("ImageUploader1");

	var UploadPane=document.getElementById("UploadPane");
	
	while (UploadPane.childNodes.length > 0){
		UploadPane.removeChild(UploadPane.childNodes[0]);
	}

	//Fix Opera applet z-order bug
	if (__browser.isOpera){
		UploadPane.style.height = "auto";
		UploadPane.style.overflow = "visible";
	}


	//Handle drag & drop.
	if (__browser.isIE || __browser.isSafari){
		var target = __browser.isIE ? UploadPane : document.body;
		target.ondragenter = function(){
			var e=window.event;
			var data = e.dataTransfer;
			if (data.getData('Text')==null){
				this.ondragover();
				data.dropEffect="copy";
				allowDrag=true;
			}
			else{
				allowDrag=false;
			}
		}
		
		target.ondragover=function(){
			var e = window.event;
			e.returnValue = !allowDrag;
		}

		target.ondrop = function(){
			var e = window.event;
			this.ondragover();
			e.dataTransfer.dropEffect = "none";
			processDragDrop();
		}
	}
	else {
		window.captureEvents(Event.DRAGDROP);
		window.addEventListener("dragdrop", function(){
				processDragDrop();
			}, true);
	}

}

function processDragDrop(){
	alert("Adding files with drag & drop can not be implemented in standard version due security reasons. However it can be enabled in private-label version."+
		"\r\n\r\nFor more information please contact us at ÷ñÒ784343923êÖ0õæ÷sales@aurigma.com÷ñÒ784343923êÖ1õæ÷");
	if (imageUploader1){
		//imageUploader1.AddToUploadList();
	}
}

//To identify items in upload list, GUID are used. However it would work 
//too slow if we use GUIDs directly. To increase performance, we will use 
//hash table which will map the guid to the index in upload list. 

//This function builds and returns the hash table which will be used for
//fast item search.
function getGuidIndexHash(){
	var uploadFileCount = imageUploader1.getUploadFileCount();
	var guidIndexHash = new Object();
	for (var i = 1; i <= uploadFileCount; i++){
		guidIndexHash[imageUploader1.getUploadFileGuid(i)] = i;
	}
	return guidIndexHash;
}

//This function returns HTML which represent the single item in the custom upload pane.
//It contains of the Thumbnail object and form elements for each piece of data (in our 
//case - title and description). If you want to upload extra data, you should write
//additional form elements here.
//
//It is highly recommended not to copy this function into the main HTML page to 
//avoid problems with activation of ActiveX controls in Internet Explorer with
//security update 912945. You can read more detailed about activation on Microsoft website:
//
//http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/overview/activating_activex.asp 
function addUploadFileHtml(index){
	var guid = imageUploader1.getUploadFileGuid(index);
	var fileName = imageUploader1.getUploadFileName(index);

	var h = "<table cellspacing=\"5\"><tbody>";
	h += "<tr>";
	h += "<td class=\"Thumbnail\" align=\"center\" valign=\"middle\">";

	//Add thumbnail control and link it with Image Uploader by its name and GUID.
	var tn = new ThumbnailWriter("Thumbnail" + uniqueId, 96, 96);
	//Copy codebase and version settings from ImageUploaderWriter instance.
	tn.activeXControlCodeBase = iu.activeXControlCodeBase;
	tn.activeXControlVersion = iu.activeXControlVersion;
	tn.javaAppletCodeBase = iu.javaAppletCodeBase;
	tn.javaAppletCached = iu.javaAppletCached;
	tn.javaAppletVersion = iu.javaAppletVersion;

	tn.addParam("ParentControlName", "ImageUploader1");
	tn.addParam("Guid", imageUploader1.getUploadFileGuid(index));
	h += tn.getHtml();

	h += "</td>";
	h += "<td valign=\"top\">";

	//Add Title element.
	h += "Title:
";
	h += "<input id=\"Title" + uniqueId + "\" class=\"Title\" type=\"text\" />
";

	//Add Description element.
	h += "Description:
";
	h += "<textarea id=\"Description" + uniqueId + "\" class=\"Description\"\"></textarea>";

	h += "</td>";
	h += "</tr>";
	h += "<tr>";
	h += "<td align=\"center\"><a href=\"#\" onclick=\"return Remove_click('" + guid + "');\">Remove</a></td>";
	h += "<td></td>";
	h += "</tr>";
	h += "</tbody></table>";

	//Create DIV element which will represent the upload list item.
	var div = document.createElement("div");
	div.className = "UploadFile";
	div.innerHTML = h;
	div._guid = guid;
	//_uniqueId is used for fast access to the Title and Description form elements.
	div._uniqueId = uniqueId;

	//Append this upload list item to the custom upload pane.
	document.getElementById("UploadPane").appendChild(div);

	//Increase the ID to guaranty uniqueness.
	uniqueId++;
}

//Synchronize custom upload pane with Image Uploader upload list when 
//some files are added or removed.
function ImageUploader_UploadFileCountChange(){
	if (imageUploader1){
		var uploadFileCount  = imageUploader1.getUploadFileCount();

		//Files are being added.
		if (prevUploadFileCount <= uploadFileCount){
			for (var i = prevUploadFileCount + 1; i <= uploadFileCount; i++){
				addUploadFileHtml(i);
			}
		}
		//Files are being removed.
		else{
			var guidIndexHash = getGuidIndexHash();
			var UploadPane = document.getElementById("UploadPane");
			var i = UploadPane.childNodes.length - 1;
			while (i >= 0){
				if (guidIndexHash[UploadPane.childNodes[i]._guid] == undefined){
					UploadPane.removeChild(UploadPane.childNodes[i]);
				}
				i--;
			}
		}

		prevUploadFileCount = uploadFileCount;

		document.getElementById("UploadButton").disabled = (uploadFileCount == 0);
	}
}

//Append the additional data entered by the user (title and description)
//to the upload. If you add more fields, do not forget to modify this event 
//handler to call AddField for these fields.
function ImageUploader_BeforeUpload(){
	var guidIndexHash = getGuidIndexHash();

	var UploadPane = document.getElementById("UploadPane");

	for (var i = 0; i < UploadPane.childNodes.length; i++){
		var div = UploadPane.childNodes[i];

		var index = guidIndexHash[div._guid];

		//Description will be sent as a native Description POST field 
		//provided by Image Uploader.
		imageUploader1.setUploadFileDescription(index,
			document.getElementById("Description" + div._uniqueId).value);

		//Title will be sent as a custom Title_N POST field, where N is an 
		//index of the file.
		imageUploader1.AddField("Title_" + index, document.getElementById("Title" + div._uniqueId).value);
	}
	[b]imageUploader1.AddField("FilesPerOnePackageCount", imageUploader1.getFilesPerOnePackageCount());[/b]
}

//This function is used to handle Remove link click. It removes an item 
//from the custom upload pane by specified GUID.
function Remove_click(guid){
	var guidIndexHash = getGuidIndexHash();
	imageUploader1.UploadFileRemove(guidIndexHash[guid]);
}

//This function posts data on server.
function UploadButton_click(){
	imageUploader1.Send();
}

upload.aspx
Code:
<%@ Page Language="C#" AutoEventWireup="True" Debug="true" ValidateRequest="false" %>

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>

<script runat="server">
	//This variable specifies relative path to the folder, where the gallery with uploaded files is located.
	//Do not forget about the slash in the end of the folder name.
	private string galleryPath = "../Gallery/";
	
	private void Page_Load(System.Object sender, System.EventArgs e)
	{
		int packageIndex = Int32.Parse(Request.Form["PackageIndex"]);
		[b]int filesPerOnePackageCount = Int32.Parse(Request.Form["FilesPerOnePackageCount"]);[/b]

		//If we receive the first file, we delete all files and thumbnails we uploaded before.
		if (packageIndex == 0)
		{
			//Delete source files.
			DirectoryInfo dir = new DirectoryInfo(Server.MapPath(galleryPath));
			foreach (FileInfo file in dir.GetFiles())
			{
				file.Delete();
			}
			//Delete thumbnails.
			dir = new DirectoryInfo(Server.MapPath(galleryPath) + "/Thumbnails");
			foreach (FileInfo file in dir.GetFiles())
			{
				file.Delete();
			}
		}

		XmlDocument descriptions = new XmlDocument();
		//If we receive the first file then
		//we start from empty file with descriptions
		if (packageIndex == 0)
		{
			descriptions.AppendChild(descriptions.CreateElement("files"));
		}
		else
		{
			descriptions.Load(Server.MapPath(galleryPath + "Descriptions.xml"));
		}
		
		//Get total number of uploaded files (all files are uploaded in a single package).
		int fileCount = Int32.Parse(Request.Form["FileCount"]);

		//Iterate through uploaded data and save the original file, thumbnail, and description.
		[b]for (int i = 1; i <= fileCount; i++)[/b]
		{
			HttpPostedFile sourceFile = Request.Files["SourceFile_" + i];

			string fileName = GetSafeFileName(sourceFile.FileName);
			sourceFile.SaveAs(Server.MapPath(galleryPath + fileName));
			
			Request.Files["Thumbnail1_" + i].SaveAs(Server.MapPath(galleryPath + "Thumbnails/" + fileName + ".jpg"));

			//Save file info.
			XmlElement xmlFile = descriptions.CreateElement("file");
			xmlFile.SetAttribute("name", fileName);
			xmlFile.SetAttribute("width", Request.Form["Width_" + i]);
			xmlFile.SetAttribute("height", Request.Form["Height_" + i]);
			[b]int realIndex = i + packageIndex * filesPerOnePackageCount;
			xmlFile.SetAttribute("title", Request.Form["Title_" + realIndex]);[/b]
			xmlFile.SetAttribute("description", Request.Form["Description_" + i]);

			descriptions.DocumentElement.AppendChild(xmlFile);
		}

		descriptions.Save(Server.MapPath(galleryPath + "Descriptions.xml"));
	}

	//This method verifies whether file with such name already exists
	//and if so, construct safe filename name (to avoid collision).
	private string GetSafeFileName(string fileName)
	{
		string newFileName = fileName;
		int j = 1;
		while (File.Exists(Server.MapPath(galleryPath + newFileName)))
		{
			newFileName = j + "_" + fileName;
			j++;
		}
		return newFileName;
	}
</script>

Edited by user Tuesday, December 18, 2007 4:45:41 PM(UTC)  | Reason: Not specified

Sincerely yours,
Alex Makhov

UserPostedImage Follow Aurigma on Twitter!
Alex Makhov  
#5 Posted : Friday, March 02, 2007 1:07:17 PM(UTC)
Alex Makhov

Rank: Advanced Member

Groups: Member
Joined: 8/3/2003(UTC)
Posts: 998

Hello,

Here is the BasicDemo sample rewritten to be used with PHP4 (original sample works on PHP5).

index.php
Code:

<!--BEGIN-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Aurigma Image Uploader - Basic Demo</title>

	<script type="text/javascript" src="../iuembed.js"></script>

	<link href="style.css" type="text/css" rel="stylesheet" />
</head>
<body>
	


		This simple application is a quick start demo with minimum settings. It demonstrates
		how to:
	
	<ul>
		<li>Display thumbnails in two-pane layout.</li>
		<li>Upload the file with 120x120 thumbnail.</li>
		<li>Redirect to another page after successful upload.</li>
	</ul>
	<fieldset>
		<legend>Note</legend>This demo application <strong>deletes all previously uploaded files</strong>.
		Keep in mind that it is a feature of this demo, not of Image Uploader itself. If
		you <strong>do not want to delete uploaded files</strong>, you should modify the
		upload processing page specified by the <strong>Action</strong> parameter.
	</fieldset>

	<script type="text/javascript">
//<![CDATA[
//Create JavaScript object that will embed Image Uploader to the page.
var iu = new ImageUploaderWriter("ImageUploader1", 650, 400);

//For ActiveX control full path to CAB file (including file name) should be specified.
iu.activeXControlCodeBase = "../ImageUploader4.cab";
iu.activeXControlVersion = "4,1,21,0";

//For Java applet only path to directory with JAR files should be specified (without file name).
iu.javaAppletCodeBase = "../";
iu.javaAppletCached = true;
iu.javaAppletVersion = "2.1.21.0";

iu.showNonemptyResponse = "off";

//Configure appearance.
iu.addParam("PaneLayout", "TwoPanes");
iu.addParam("ShowDebugWindow", "true");
iu.addParam("EnableRotate", "false");
iu.addParam("BackgroundColor", "#ccccff");

//Configure thumbnail settings.
iu.addParam("UploadThumbnail1FitMode", "Fit");
iu.addParam("UploadThumbnail1Width", "120");
iu.addParam("UploadThumbnail1Height", "120");
iu.addParam("UploadThumbnail1JpegQuality", "60");

//Configure URL files are uploaded to.
iu.addParam("Action", "upload.php");

//Configure URL where to redirect after upload.
iu.addParam("RedirectUrl", "gallery.php");

//Tell Image Uploader writer object to generate all necessary HTML code to embed 
//Image Uploader to the page.
iu.writeHtml();
//]]>
	</script>

</body>
</html>
<!--END-->

upload.php
Code:

<?php
//This variable specifies relative path to the folder, where the gallery with uploaded files is located.
//Do not forget about the slash in the end of the folder name.
$galleryPath = "../Gallery/";

$absGalleryPath = realpath($galleryPath) . "/";
$absThumbnailsPath = realpath($galleryPath . "Thumbnails/") . "/";

function saveUploadedFiles()
{
	global $absGalleryPath, $absThumbnailsPath;	
	//First of all, clear files and data uploaded at previous time.
	
	//Delete source files.
	$handle = opendir($absGalleryPath);
	while ($file = readdir($handle)) 
	{
		if (is_file($galleryPath . "/" .$file))
		{
			unlink($galleryPath . "/" . $file);
		}
	}
	closedir($handle); 

	//Delete thumbnails
	$handle = opendir($absThumbnailsPath);	
	
	closedir($handle);

	//NOTE: If you do not want to delete previously uploaded files, just 
	//remove or comment out the code above.
	
	//Create XML file which will keep information about files (image dimensions, description, etc). 
	//XML is used solely for brevity. In real-life application most likely you will use database instead.	
	$descriptions =domxml_new_doc('1.0'); 
	$root = $descriptions->append_child($descriptions->create_element("files"));
	
	//Get total number of uploaded files (all files are uploaded in a single package).
	$fileCount = $_POST ["FileCount"];
	
	//Iterate through uploaded data and save the original file, thumbnail, and description.
	for ($i = 1; $i <= $fileCount; $i++)
	{
		//Get source file and save it to disk.
		$sourceFileField = "SourceFile_" . $i;
		if (!$_FILES[$sourceFileField]['size'])
		{
			return;	
		}
		$fileName = getSafeFileName($_FILES[$sourceFileField]['name']);
		move_uploaded_file($_FILES[$sourceFileField]['tmp_name'], $absGalleryPath . "/" . $fileName);

		//Get first thumbnail (the single thumbnail in this code sample) and save it to disk.
		$thumbnail1Field = "Thumbnail1_" . $i;
		if (!$_FILES[$thumbnail1Field]['size'])
		{
			return;	
		}
		move_uploaded_file($_FILES[$thumbnail1Field]['tmp_name'], $absGalleryPath . "/Thumbnails/" . $fileName );

		//Save file info.
		$xmlFile = $descriptions->create_element("file");
		$xmlFile->set_attribute("name", $fileName);
		$xmlFile->set_attribute("width", $_POST ['Width_' . $i]);
		$xmlFile->set_attribute("height", $_POST ['Height_' . $i]);
		$xmlFile->set_attribute("description", $_POST ['Description_' . $i]);
		$root->append_child($xmlFile);
		
	}
	$descriptions->dump_file($absGalleryPath ."Descriptions.xml");
	
}

function getSafeFileName($fileName)
{
	global $absGalleryPath;
	
	$newFileName = $fileName;
	$j = 1;
	while (file_exists($absGalleryPath . "/" . $newFileName))
	{
		$newFileName = $j . "_" . $fileName;
		$j = $j + 1;
	}
	return $newFileName;	
}

saveUploadedFiles();

?>

gallery.php
Code:

<?php

//This variable specifies relative path to the folder, where the gallery with uploaded files is located.
//Do not forget about the slash in the end of the folder name.
$galleryPath = "../Gallery/";
$absGalleryPath = realpath($galleryPath) . "\\";

function getAttribute($name, $att)
{
   foreach($att as $i)
   {
       if($i->name()==$name)
           return $i->value();       
   }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Aurigma Image Uploader - Uploaded Files</title>
	<link href="style.css" type="text/css" rel="stylesheet" />
</head>
<body>
	


		<a href="index.php">Upload New Files</a>
	

	<table width="100%">

<?php

function parseResult()
{
	global $absGalleryPath, $galleryPath;	

	$colCount = 4;
	$showfile = file_get_contents($absGalleryPath . "Descriptions.xml");
	$descriptions = domxml_open_mem($showfile);
	$root = $descriptions->document_element();

	if (!$root)
	{
		echo "Error! Root element not found!";
	}
	$children = $root->child_nodes();
	if (!$children)
	{
		echo "Error! Child elements not found!";
	}
	$count = count($children);

	for ($i = 0; $i < $count; $i++)
	{	
		$xmlFile = $children[$i];
					
		if ($i % $colCount == 0)
		{
			echo "<tr>";
		}
		$attr = $xmlFile->attributes();
		$fileName = rawurlencode(getAttribute("name",$attr));
			
				echo "<td>";
				echo "<a href='$galleryPath$fileName' target='_blank'>";
				echo "<img src='".$galleryPath."Thumbnails/".$fileName."' alt='".htmlentities(getAttribute('name',$attr))."' />";
				echo "</a>";
				echo "
";
				echo "
";
				echo "<b>Name:</b>";
				echo htmlentities(getAttribute("name",$attr));
				echo "
";
				echo "<b>Dimensions:</b>";
				echo htmlentities(getAttribute("width",$attr));
				echo "x";
				echo htmlentities(getAttribute("height",$attr));
				echo "
";
				echo "<b>Description:</b>";
				echo htmlentities(getAttribute("description",$attr));
				echo "</td>";

		if (( ( $i + 1 ) % $colCount == 0 ) or ( $i == $count - 1))
		{
			echo "</tr>";
		}
	}
}

parseResult();
?>
	</table>
</body>
</html>


Additional dependencies: iuembed.js and style.css can be taken from the standard PHP5 sample.

Edited by user Tuesday, December 18, 2007 4:46:00 PM(UTC)  | Reason: Not specified

Sincerely yours,
Alex Makhov

UserPostedImage Follow Aurigma on Twitter!
reza.laghaei  
#6 Posted : Tuesday, April 03, 2007 5:29:32 PM(UTC)
reza.laghaei

Rank: Member

Groups: Member
Joined: 4/3/2007(UTC)
Posts: 1

I have the following error.

Fatal error: Call to undefined function: load() error on line 16.

Line 16: $dom = DOMDocument::load( $_FILES['file']['tmp_name'] );

Please let me know if there is any problem with with code.

Thank you

Regards,

Reza:(


Reza.laghaei@mrltechnologies.com
George Ulyanov  
#7 Posted : Tuesday, April 03, 2007 8:32:15 PM(UTC)
George Ulyanov

Rank: Advanced Member

Groups: Member
Joined: 7/26/2006(UTC)
Posts: 203

Hello Reza,

I guess you are using PHP4. But the samples (most of them) have written for PHP5.
Only last sample here has written for PHP4.

Edited by user Thursday, July 09, 2009 7:41:16 PM(UTC)  | Reason: Not specified

Best regards,
George Ulyanov
Users browsing this topic
Similar Topics
Helper Scripts For Image Uploader topic update (Image Uploader)
by Alex Makhov 10/26/2006 1:33:00 PM(UTC)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.