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

Notification

Icon
Error

Options
Go to last post Go to first unread
dotcomtim  
#1 Posted : Friday, December 1, 2006 10:00:41 AM(UTC)
dotcomtim

Rank: Member

Groups: Member
Joined: 11/29/2006(UTC)
Posts: 14

I found a script that does what I need, and tested it out works prefect! Just needs a few additions, anyone who can help I would be grateful.

The photos in the array have to be added to the upload list, if they are not there is an error generated. Prefect!

a) Needs, to check if a photo that isn’t in the list can not be uploaded.

b) Remove photos from the list.

You can remove photo7.jpg from the list but you can’t remove photo6.jpg unless you remove photo7.jpg first.

c) Stop removing photos from the list at 6 so photo1 thru photo5 are always required.

Code:
var files = new Array("photo1.jpg", "photo2.jpg", "photo3.jpg", "photo4.jpg", "photo5.jpg", "photo6.jpg", "photo7.jpg")
function showFileList()
{
	var uploadFiles = new Object();
	for (i=1;i<=ImageUploader1.UploadItems.Count;i++)
	{
		var uploadItem = ImageUploader1.UploadItems.Item(i);
		uploadFiles[uploadItem.fileName.split("\\").reverse()[0]]=1;
	}
	var fileList = document.getElementById("fileList");
	while (fileList.options.length>0)
	{
		fileList.options.remove(0);
	}
	for (i=0;i<files.length;i++)
	{
		var fileName = files[i];
		if (uploadFiles[fileName]==undefined)
		{
	    	var option = document.createElement("OPTION");
			fileList.options.add(option);
			option.innerText = fileName;
			option.value = fileName;
		}
	}
}
function uploadClick()
{
	if (document.getElementById("fileList").options.length>0)
	{
		alert("Please select all photos specified in your upload cart.");
	}
	else
	{
		ImageUploader1.Send();
	}
}



Thanks

Edited by user Tuesday, February 19, 2008 6:09:43 PM(UTC)  | Reason: Not specified

dotcomtim  
#2 Posted : Sunday, December 3, 2006 6:15:29 AM(UTC)
dotcomtim

Rank: Member

Groups: Member
Joined: 11/29/2006(UTC)
Posts: 14

How about a custom script? can we get a customize javascript to pull off what we require, as I have tried it all.. Mind you I don't program..

Code:
for (i=ImageUploader1.UploadItems.Count; i>=1; i--)
{
	var uploadItem = ImageUploader1.UploadItems.Item(i);
	if (uploadItem.FileName != 'photo1.jpg')
	{
		alert(uploadItem.FileName);
		ImageUploader1.UploadItems.Remove(i);
		i--;
	}
}


I even tried the following and nothing.. help!

Edited by user Tuesday, February 19, 2008 6:10:22 PM(UTC)  | Reason: Not specified

Alex Makhov  
#3 Posted : Monday, December 4, 2006 7:01:39 PM(UTC)
Alex Makhov

Rank: Advanced Member

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

Hello,

UploadItem API is not supported any more. Use the methods of UploadFile API such as UploadFileName Property.

Edited by user Tuesday, February 19, 2008 6:11:17 PM(UTC)  | Reason: Not specified

Sincerely yours,
Alex Makhov

UserPostedImage Follow Aurigma on Twitter!
dotcomtim  
#4 Posted : Tuesday, December 5, 2006 8:48:14 AM(UTC)
dotcomtim

Rank: Member

Groups: Member
Joined: 11/29/2006(UTC)
Posts: 14

Change my script get the same results
Code:
<script for="ImageUploader1" event="UploadFileCountChange">
var ImageUploader=getImageUploader("ImageUploader1");
for (i=ImageUploader.getUploadFileCount(); i>=1; i--)
{
    if (ImageUploader.getUploadFileName(i) != 'photo1.jpg')
    {
        alert(ImageUploader.getUploadFileName(i));
        ImageUploader.UploadFileRemove(i);
    }
}
</script>


Right know as above no files get added as getUploadFileName actually also includes L:\Photos\20 Everett Rd\stills\photo1.jpg

Is there an equivalent function that get just the file name without the directory structure? Or is there a method of removing that I am missing?

Edited by user Tuesday, February 19, 2008 6:10:38 PM(UTC)  | Reason: Not specified

Alex Makhov  
#5 Posted : Wednesday, December 6, 2006 7:16:33 PM(UTC)
Alex Makhov

Rank: Advanced Member

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

Hello!

That’s my 500-th topic in this forum! :P

I have made a special script for you which compares the list of files to be uploaded and if id does not correspond to the list of the files specified in the array, it shows the error message and cancels the upload process.

Here is the code:
Code:
function extractFileName(path)
{
	var idx1;
	var idx2;
	var idx = -1;
	var fileName;
	idx1 = path.lastIndexOf("/");
	idx2 = path.lastIndexOf("\\");
	idx = (idx1 > idx2) ? idx1 : idx2;
	if (idx > -1)
	{
		return path.substring(idx + 1, idx.length);
	}
	else
	{
		return path;
	}
}

var files = new Array("photo1.jpg", "photo2.jpg", "photo3.jpg", "photo4.jpg")

function ImageUploader_BeforeUpload()
{
	var imageUploader = getImageUploader("ImageUploader1");
	var missedFiles = new Object();
	var extraFiles = new Object();
	var count = imageUploader.getUploadFileCount();	

	var extraCount = 0;
	for (i = 1; i <= count; i++)
	{
		var uploadFileName = extractFileName(imageUploader.getUploadFileName(i));
		var foundSimilar = false;
		for (j = 0; j < files.length; j++)
		{			
			var currentFileName = files[j];
			if (uploadFileName == currentFileName)
			{
				foundSimilar = true;
				break;
			}
		}
		if (!foundSimilar)
		{
			extraFiles[extraCount] = uploadFileName;
			extraCount++;
		}
	}
	var missedCount = 0;
	for (j = 0; j < files.length; j++)
	{
		var currentFileName = files[j];		
		var foundSimilar = false;
		for (i = 1; i <= count; i++)
		{			
			var uploadFileName = extractFileName(imageUploader.getUploadFileName(i));
			if (uploadFileName == currentFileName)
			{
				foundSimilar = true;
				break;
			}
		}
		if (!foundSimilar)
		{
			missedFiles[missedCount] = currentFileName;
			missedCount++;
		}
	}
	var message = "";
	if (extraCount > 0)	//	Some extra files have been added to the upload list.
	{
		message += "The following files are extra:\n";
		for (i = 0; i < extraCount; i++)
		{
			message += extraFiles[i] + "\n";
		}
	}
	if (missedCount > 0)	//	Not all of the files from the list have been added to the upload list.
	{
		message += "The following files are missed:\n";
		for (i = 0; i < missedCount; i++)
		{
			message += missedFiles[i] + "\n";
		}
	}
	if (message.length > 0)
	{
		alert(message);
		return false;	//	Deny upload.
	}
	else
	{
		return true;	//	Allow upload.
	}
}
…
iu.addEventListener("BeforeUpload", "ImageUploader_BeforeUpload");

Edited by user Tuesday, February 19, 2008 6:11:47 PM(UTC)  | Reason: Not specified

Sincerely yours,
Alex Makhov

UserPostedImage Follow Aurigma on Twitter!
dotcomtim  
#6 Posted : Thursday, December 7, 2006 12:34:21 AM(UTC)
dotcomtim

Rank: Member

Groups: Member
Joined: 11/29/2006(UTC)
Posts: 14

Works perfect, I thank you very much!
Users browsing this topic
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.