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

Notification

Icon
Error

Options
Go to last post Go to first unread
quattro  
#1 Posted : Saturday, May 1, 2004 7:22:00 AM(UTC)
quattro

Rank: Member

Groups: Member
Joined: 5/1/2004(UTC)
Posts: 14

I'm using the php sample so far. Is there sample code for having each upload put in the galler in a folder using the author's name? Also, I must say, I've tested just about every file/image upload out there, and by far this is light years ahead of all of them. Great Job!
HalR  
#2 Posted : Sunday, May 2, 2004 5:25:00 AM(UTC)
HalR

Rank: Member

Groups: Member
Joined: 4/30/2004(UTC)
Posts: 5

In the Upload.php page, Just change the gallerypath to a dynamic path. I use a session to store the $username upon login then my gallery path looks like this,
Code:
$galleryPath = realpath("$username/");  
and then the same thing for the Picturegallery page if you are using that one.

Edited by user Monday, December 24, 2007 5:50:18 PM(UTC)  | Reason: Not specified

quattro  
#3 Posted : Thursday, May 6, 2004 4:00:00 PM(UTC)
quattro

Rank: Member

Groups: Member
Joined: 5/1/2004(UTC)
Posts: 14

I put this in the Upload.php, but it still puts it in the root of the gallery folder:
Code:
$galleryPath = realpath(Gallery/" . $author);

Edited by user Monday, December 24, 2007 5:55:47 PM(UTC)  | Reason: Not specified

Andrew  
#4 Posted : Thursday, May 6, 2004 4:10:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 866

Thanks: 2 times
Was thanked: 26 time(s) in 26 post(s)
In the standard PHP code sample $author variable is filled after initialization of $galleryPath. So if you want to use it, you should fill it first. Could you post full upload.php here (or submit case it)?

Edited by user Friday, May 23, 2008 4:08:59 PM(UTC)  | Reason: Not specified

quattro  
#5 Posted : Friday, May 7, 2004 10:43:00 AM(UTC)
quattro

Rank: Member

Groups: Member
Joined: 5/1/2004(UTC)
Posts: 14

oops, forgot that, I put the statement defining the author variable before the initialization of the gallerypath. I think I've narrowed the problem down to the fact that I'm using this on win2k, it seems problems with mkdir aren't uncommon with win2k. I have all the permissions set correctly though. Any thoughts on how I might handle this. I need to have each upload put in its own directory. It doesn't matter what the directory name is, could be just a date and timestamp, or the author name, taken from image submit page. If I can get the demo working then I'm ready to purchase so I can bring it into production. Thanks in advance for you assistance. Here is the upload.php I am using:
Code:
<?php
//*********************************************************************************
// Aurigma Image Uploader Sample Script
// Copyright(c) Aurigma Inc. 2002-2003
// WWW: http://www.aurigma.com 
//*********************************************************************************

$author = $HTTP_POST_VARS ['Author' . $i];
$galleryPath = "D:\inetpub\fotoshop\upload\imageup\PHP\Gallery\author");

//Delete source images
$handle=opendir($galleryPath . "/");
if (!$handle)
{	
	mkdir($galleryPath);

}
else
{	
	while ($file = readdir($handle)) 
	{
		if (is_file($galleryPath . "/" .$file))
		{
			unlink($galleryPath . "/" . $file);
		}
	}
	closedir($handle); 
}

//Delete thumbnails
$handle=opendir($galleryPath . "/Thumbnails/");
if (!$handle)
{	
	mkdir($galleryPath . "/Thumbnails/", 0700);
}
else
{	                                      
	while ($file = readdir($handle)) 
	{
		if (is_file($galleryPath . "/Thumbnails/" . $file))
		{
			unlink($galleryPath . "/Thumbnails/" . $file);
		}
	}
	closedir($handle); 
}

//Make file to hold descriptioons
if(file_exists($galleryPath . "/Descriptions.txt"))
{
	unlink($galleryPath . "/Descriptions.txt");
}

$fileCount = $HTTP_POST_VARS ["FileCount"];

$descrFile = fopen($galleryPath . "/Descriptions.txt", "wb");

//Read Author name and images count
$author = $HTTP_POST_VARS ['Author' . $i];
fwrite($descrFile, $fileCount);
fwrite($descrFile, "\r\n");
fwrite($descrFile, $author);
fwrite($descrFile, "\r\n");

//process received files	
for($i=1;$i<=$fileCount;$i++)
{
	$imageName = "SourceFile_" . $i;
	$size=$_FILES[$imageName][size]; 

	//Check whether file with such name already exists and if so,  	
	//construct safe filename name (to avoid collision)
	$fileName = $_FILES[$imageName][name];
	$newFileName = $fileName;
	$J = 1;
	while (file_exists($galleryPath . "/" . $newFileName))
	{
		$newFileName = $J . "_" . $fileName;
		$J = $J + 1;
	}
	$fileName = $newFileName;
	
	if($size) 
	{ 
		copy($_FILES[$imageName][tmp_name], $galleryPath . "/" . $fileName);		
		$width = $HTTP_POST_VARS ['Width_' . $i];
		$height = $HTTP_POST_VARS ['Height_' . $i];
		$description = $HTTP_POST_VARS ['Description_' . $i];
		fwrite($descrFile, $fileName);
		fwrite($descrFile, "\r\n");
		fwrite($descrFile, $width);
		fwrite($descrFile, "\r\n");
		fwrite($descrFile, $height);
		fwrite($descrFile, "\r\n");
		fwrite($descrFile, $description);
		fwrite($descrFile, "\r\n");
	}
	$thumbnailName = "Thumbnail1_" . $i;
	$size=$_FILES[$thumbnailName][size];
	if($size) 
	{ 
		copy($_FILES[$thumbnailName][tmp_name], $galleryPath . "/Thumbnails/" . $fileName . ".jpg");
	}
}
fclose($descrFile);
?>

Edited by user Friday, May 23, 2008 4:10:46 PM(UTC)  | Reason: Not specified

quattro  
#6 Posted : Friday, May 7, 2004 10:49:00 AM(UTC)
quattro

Rank: Member

Groups: Member
Joined: 5/1/2004(UTC)
Posts: 14

ignore the gallerypath line in the upload.php code I posted. I was testing to see if it would just create a directory called author(it wouldn't). Replace this:
Code:
$galleryPath = "D:\inetpub\fotoshop\upload\imageup\PHP\Gallery\author");
with this:
Code:
$galleryPath = realpath(Gallery/" . $author);
Thanks again!

Edited by user Monday, December 24, 2007 5:50:49 PM(UTC)  | Reason: Not specified

Andrew  
#7 Posted : Friday, May 7, 2004 1:03:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 866

Thanks: 2 times
Was thanked: 26 time(s) in 26 post(s)
First of all, code sample contains a typo (which does not influence it though): instead of $HTTP_POST_VARS ['Author' . $i] you should use $HTTP_POST_VARS ['Author']. Besides, I tried to reproduce the problem. It fails to create the folder indeed, however if the folder with such name exists, it correctly puts files there. So I guess it is a problem with permissions. Try to give full rights to Everyone and run the script (do not forget to remove rights for Everyone when you will test it). If it succeeds, it is definitely permissions problem. By the way, are you running PHP under IIS or Apache?
quattro  
#8 Posted : Saturday, May 8, 2004 2:07:00 AM(UTC)
quattro

Rank: Member

Groups: Member
Joined: 5/1/2004(UTC)
Posts: 14

Thanks for the quick response Andrew. it is under IIS. Don't think it's permissions. I tried another test, deleting the Thumbnails directory. The script had no problem creating that direcory.
quattro  
#9 Posted : Saturday, May 8, 2004 2:42:00 AM(UTC)
quattro

Rank: Member

Groups: Member
Joined: 5/1/2004(UTC)
Posts: 14

Did another test...it's definitely a problem with the way the script is written that win2k or IIS don't like. Under the delete thumbnails section, if I change Thumbnails to $author the thumbnail directory was created with the author name. So I figured that the mkdir needs a path plus the actual new directory name. I don't think mdkdir likes dealing with a predefined path for some reason. Keep in mind I just started playing with php recently, so don't laugh at how I explain my troubleshooting. :) So, I figured what the heck, I'll define the gallery path two different ways in the beginning of the script, one that mkdir and win2k/iis will like and one for the rest of the script. Well, it worked, lol. Here's the changes I made(I'm sure this isn't PROPER, lol):
Code:
$author = $HTTP_POST_VARS ['Author'];
$galleryPath = realpath("Gallery");
mkdir($galleryPath . "/$author/", 0700);
$galleryPath = realpath("Gallery" . "/" . $author);
I'm sure there is a more elegant way of doing this and would appreciate if you could give me the PROPER changes to the script that will make it work. Andrew, thanks again for your prompt follow up and the testing you did yourself. Feel free to send a free license my way for finding this bug :P HEHEHEHEHEHE Have a great weekend.

Edited by user Monday, December 24, 2007 5:51:05 PM(UTC)  | Reason: Not specified

quattro  
#10 Posted : Saturday, May 8, 2004 2:49:00 AM(UTC)
quattro

Rank: Member

Groups: Member
Joined: 5/1/2004(UTC)
Posts: 14

Ohhhhh...another question. Is there a way to keep the new images from overwriting the existing images? For example, author John uploads three files. They go in the "John" directory. A few minutes later, John uploads two more files, the desired result would be that those two new files "join" the existing three files in the directory rather than replace them(and maybe even the description.txt is appeneded with the new file names). Thanks again!
Andrew  
#11 Posted : Monday, May 10, 2004 12:21:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 866

Thanks: 2 times
Was thanked: 26 time(s) in 26 post(s)
Just remove code which deletes files and thumbnails. Besides before saving file, you should add code which checks if file with such name exists and if so, append some suffix to its name to avoid overwriting.
quattro  
#12 Posted : Tuesday, May 11, 2004 2:46:00 AM(UTC)
quattro

Rank: Member

Groups: Member
Joined: 5/1/2004(UTC)
Posts: 14

Thanks again Andrew, I thought that might be all that was necessary, but wasn't sure. Since I'm new to PHP are there any links or code snippets that might get me started as far as checking filename and appending a suffix? The check in the sample doesn't seem to work(the default sample would overwrite files if they had the same name). Do you forsee any problems that might result from my crude fix to creating the directory? Thanks!
Andrew  
#13 Posted : Tuesday, May 11, 2004 12:44:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 866

Thanks: 2 times
Was thanked: 26 time(s) in 26 post(s)
> Since I'm new to PHP are there any links or code snippets that might get me started as far as checking filename and appending a suffix? The check in the sample doesn't seem to work(the default sample would overwrite files if they had the same name). This piece of code should do this job:
Code:
// ... 

//Check whether file with such name already exists and if so,  	
//construct safe filename name (to avoid collision)

$fileName = $_FILES[$imageName][name];

$newFileName = $fileName;
$J = 1;
while (file_exists($galleryPath . "/" . $newFileName))
{
	$newFileName = $J . "_" . $fileName;
	$J = $J + 1;
}

$fileName = $newFileName;

//...
Make sure if you did not remove this code. > Do you forsee any problems that might result from my crude fix to creating the directory? I think it is ok since it works :)

Edited by user Monday, December 24, 2007 5:51:17 PM(UTC)  | Reason: Not specified

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.