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

Notification

Icon
Error

Options
Go to last post Go to first unread
joanmjc  
#1 Posted : Tuesday, February 9, 2010 7:24:19 PM(UTC)
joanmjc

Rank: Member

Groups: Member
Joined: 11/26/2008(UTC)
Posts: 17

Hello, I was wondering since my image uploader works so smooth now, is there a way to make the upload folder variable, since Id like each user uploads to be stored in one folder different from other user

For example if John wants to upload, i need a script to make a folder named John and everything he uploads in that session are stored in jonhs folder

5 minutes later Anna wants to upload so now there will be a new folder named Anna under Uploads folder and everything will be inside Anna's folder

Is there a script to make that happen?

Thanks
Tamila  
#2 Posted : Wednesday, February 10, 2010 3:50:16 AM(UTC)
Tamila

Rank: Advanced Member

Groups:
Joined: 3/9/2008(UTC)
Posts: 554

Was thanked: 1 time(s) in 1 post(s)
Hello,

Actually you can do it, but you should have authentication in your project. You can do it using Cookies or Sessions, or some other methods which allow to identify each user. In this case you can save pictures in separate folders.
Aurigma Support Team

UserPostedImage Follow Aurigma on Twitter!
G4XTR  
#3 Posted : Wednesday, February 10, 2010 4:06:43 AM(UTC)
G4XTR

Rank: Member

Groups: Member
Joined: 12/23/2009(UTC)
Posts: 15

Thanks: 1 times
Joanmjc,

Depending on what script type you're using, you can add the functionality to the script to create a new directory on the server before uploading. This can be for example a random numer or timestamp. This variable can be used to assign the upload location.

You can also extend this concept to have a seperate script where users can select an upload location, a variable which is then passed on to the uploader.

joanmjc  
#4 Posted : Thursday, February 11, 2010 4:02:24 PM(UTC)
joanmjc

Rank: Member

Groups: Member
Joined: 11/26/2008(UTC)
Posts: 17

I see, now the thing is, where can I find example php codes of it?
Tamila  
#5 Posted : Thursday, February 11, 2010 6:24:33 PM(UTC)
Tamila

Rank: Advanced Member

Groups:
Joined: 3/9/2008(UTC)
Posts: 554

Was thanked: 1 time(s) in 1 post(s)
Hello,

Unfortunately, realization of this functionality is out of our technical support, we cannot provide you this code, because we do not know internal logic of your application.
Aurigma Support Team

UserPostedImage Follow Aurigma on Twitter!
Albertvdmeulen  
#6 Posted : Friday, February 19, 2010 12:04:49 AM(UTC)
Albertvdmeulen

Rank: Advanced Member

Groups: Member
Joined: 3/18/2009(UTC)
Posts: 46

Thanks: 3 times
Was thanked: 1 time(s) in 1 post(s)
Hi,

This is how we solved it.
We use session with the clients name and an timestamp.
Spaces are removed from the name and a special folder is made per client.

photoorder:
Code:

<?php

	
	if($_GET[sid])
	{ 
		session_id($_GET[sid]);
	}
session_start();

		//f_name,email en telefoon opslaan in session
		$f_name = $_POST['f_name'];
   		$email = $_POST['email'];
		$telefoon = $_POST['telefoon'];
   		$_SESSION['naam'] = $f_name;
		$_SESSION['email'] = $email;
		$_SESSION['telefoon'] = $telefoon;

// MK DIR 
// Maakt directory van de ingevoerde user naam
// Slaat directorynaam op in session
	 	$foldername = @$_SESSION[naam];
		$foldername = str_replace (" ", "_", $foldername);
		$date = date("YmdHis");
  		if($foldername !== ""){
  		mkdir("C:/Data/Bestellingen FTP server/upload/" . $foldername . $date, 0700);

		mkdir("../../../Thumb/". $foldername . $date, 0700);
		mkdir("../../../Thumb/". $foldername . $date . "/Thumbnails/", 0700);
    	//echo "Folder " . $foldername . " was created!<br>";
		}
 
$_SESSION['foldernaam'] = 'C:/Data/Bestellingen FTP server/upload/' . $foldername . $date ;
$_SESSION['foldershort'] = $foldername . $date ;
// END MK DIR

?>
<!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 Demos &mdash; Photo Order Demo</title>
	<link href="../common.css" type="text/css" rel="stylesheet" />

etc. etc.


And in the upload.php
Code:

<?php

	
	if($_GET[sid])
	{ 
		session_id($_GET[sid]);
	}
session_start();
?>
<?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.


	// folder where original photos are saved

		$galleryPath = $_SESSION['foldernaam'];


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



	// copy thumbnails to the correct folder
		$foldershort = $_SESSION['foldershort'];
		$galleryPathThumb = "../../../thumb/";
		$absThumbnailsPath = realpath($galleryPathThumb . $foldershort . "/Thumbnails/") . "/";

function saveUploadedFiles()
{

	// Check whether upload wasn't aborted
	if (array_key_exists('FileCount', $_POST)) {
		global $absGalleryPath, $absThumbnailsPath;

	//First of all, clear data uploaded at previous time.

	//In this code sample each file is uploaded with a separate request. It means that this
	//page will be called for each file individually (rather than once for all files). Therefore
	//we need a way to determine whether this page is called for new upload session or not.
	//
	//To do it we check a PackageIndex POST field which returns a number of the request in the upload session.
	//If it is the very first package we should delete all files and thumbnails we uploaded before.
	//Otherwise, previously uploaded files belong to the same upload session and we should not delete them.
		$packageIndex = $_POST ["PackageIndex"];

		
	// XML bestand

	//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 = new DOMDocument('1.0');

		//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($absGalleryPath . "Descriptions.xml");
		}


	//NOTE: Since each file is uploaded in a separate request (because
	//FilesPerOnePackageCount param equals to 1), you should work only
	//with POST fields with index = 1 (such as SourceFile_1, FileName_1, etc).
		if (!$_FILES["SourceFile_1"]['size'])
		{
			return;
		}
		$fileName = getSafeFileName($_FILES["SourceFile_1"]['name']);
		move_uploaded_file($_FILES["SourceFile_1"]['tmp_name'], $absGalleryPath . "/" . $fileName);

		//Get the thumbnail and save it to disk.
		if (!$_FILES["Thumbnail1_1"]['size'])
		{
			return;
		}
		move_uploaded_file($_FILES["Thumbnail1_1"]['tmp_name'], $absThumbnailsPath . $fileName . ".jpg");


	//Save file info.
		$xmlFile = $descriptions->createElement("file");
		$xmlFile->setAttribute("name", $fileName);
		// $xmlFile->setAttribute("width", $_POST ['Width_1']);
		// $xmlFile->setAttribute("height", $_POST ['Height_1']);
		$xmlFile->setAttribute("description", $_POST ['Description_1']);
		$descriptions->documentElement->appendChild($xmlFile);

		$descriptions->save($absGalleryPath . "Descriptions.xml");
	}
}


	//This method verifies whether file with such name already exists
	//and if so, construct safe filename name (to avoid collision).
function getSafeFileName($fileName)
{
	global $absGalleryPath;

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

saveUploadedFiles();
?>



Hope this can help you.

Grt,

Rob
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.