Multiple Uploads, opening directories and processing files.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Steve Mellor
Forum Commoner
Posts: 49
Joined: Thu Aug 02, 2007 8:18 am

Multiple Uploads, opening directories and processing files.

Post by Steve Mellor »

Hi there,

I am trying to write a script to upload multiple images and resize them. For uploading I usually use Colin Verot's upload class (which handles image resizing as well). The problem I have is that I want my end user to be able to select any file in a folder and then have every jpeg in that folder uploaded.

Now, before people say anything, I know that's not exactly a good thing to do and if this was a public site I would agree. This is actually part of a CMS system. the user is a photographer (and a friend) who is resizing his images first (nothing over 500k will be uploaded although he has the option of uploading up to 8 meg per file) and he's not stupid enough to put loads of strain on the server. It's a dedicated server as well and I would really like to make this function available for him as I know it will save him a lot of time.

Now, the problem I have is this:

I have currently got a form that will let him choose an image and will pass the directory on to another page. So now I need to open that directory (stored on his personal machine), choose the files to upload and upload them using the class.

Does anybody have any idea of how I can do this? If not, does anybody know another way of making this work. I am open to all suggestions.

Thank you all for your time and support and I look forward to hearing what everyone has to say :D
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

The file input element only supports one file, if you want to allow for multiple files/directories in a single element you will have to use some other technology. Adobe Flash supports multiple file selections but as far as I know not directories. Java might be able to.
Steve Mellor
Forum Commoner
Posts: 49
Joined: Thu Aug 02, 2007 8:18 am

Post by Steve Mellor »

Ah, you see this is why I wanted to be able to read from the directory. The idea was to read the content of the directory and create a self submitting form with each file in a separate file input element. The problem is I can't read the directory of the users computer.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

You can't neither retrieve any information about the path where the uploaded file was located on the client computer nor insert a predefined value into file input elements, browsers doesn't send/allow this for ovbious security reasons.
njcu
Forum Newbie
Posts: 8
Joined: Wed Aug 01, 2007 11:55 am
Location: Homestead, FL

Post by njcu »

You said this was an internal thing... this like on a LAN??? The reason why I ask is that if it is you could map his drive to the server and access the files that way.
Steve Mellor
Forum Commoner
Posts: 49
Joined: Thu Aug 02, 2007 8:18 am

Now with added FLASH

Post by Steve Mellor »

njcu wrote:You said this was an internal thing... this like on a LAN??? The reason why I ask is that if it is you could map his drive to the server and access the files that way.
No, when I said internal I meant it was limited to a company. The script will be in a password protected directory on the back of a website. Otherwise, mapping the hard drive would have been a nice way around the problem.

Well, I thought I would update this since I have found one solution only to be left with another problem. I'm now doing it in Flash. The Flash file I have is working perfectly well. It tells the server to upload the files and they are then passed along to a php script. Now I have tested this and it works with the following code to an extent:

Code: Select all

set_time_limit(0);
	
	$litter  = array(' ', '-');

	$uploadDir = "../gallery/".$_GET['foo']."/";
	$filename = str_replace($litter, "_", $_FILES['Filedata']['name']);
	$uploadFile = $uploadDir . $filename;
	move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadFile);
	chmod($uploadFile, 0777);
I am then able to resize to the correct dimensions.

Well, here's the problem. It gets to the ninth one and then freezes. The images that I am uploading aren't big at all, 200 - 300k each. I know this isn't a flash forum but I was wondering if anyone had any idea on why this could be. Is it something in the PHP that would cause a problem?

It may be the server and it may be the connection, I am aware of that. It is just odd that it seams to happen in the same place each time. Would pausing the execution of the script help at all?

Once again, any help is greatly appreciated.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Steve Mellor
Forum Commoner
Posts: 49
Joined: Thu Aug 02, 2007 8:18 am

Post by Steve Mellor »

volka wrote:see viewtopic.php?t=71990
Thanks for the link, very interesting. I'm in the process of downloading JUpload. I've never used an aplet like this on a website before though so it will, obviously, take a little playing around with.

None the less, I would still like to find out why I am having a problem with this flash version. I've built this from the ground up so I would like to solve any problems I'm having with it. It would be... satisfying.
Steve Mellor
Forum Commoner
Posts: 49
Joined: Thu Aug 02, 2007 8:18 am

Post by Steve Mellor »

Ok, just so you know, the problem does not lie with the script its self. That is working perfectly well locally. It appears the problem is:

1) The connection to the server
2) The server set-up
3) An over-load on the server

If either of these is the case then I don't see JUpload working either, but there's only one way to find out.
beinn
Forum Newbie
Posts: 8
Joined: Tue Aug 07, 2007 11:43 am

Post by beinn »

Hi Steve, just though I would drop you a line as I have exactly the same problem and started a topic yesterday before I saw yours.
Steve Mellor
Forum Commoner
Posts: 49
Joined: Thu Aug 02, 2007 8:18 am

Post by Steve Mellor »

Hay there beinn,

Well I've solved some problems already. Firstly I'm using Flash to upload the images. There's reference material for doing it at http://www.brajeshwar.com/reference/as2 ... eList.html

All you have to do is change the link

Code: Select all

http://www.yourdomain.com/
to that of your upload script. I've done a few other things with mine. I've added a pre-loader and some buttons, an item count etc. To be honest it's fairly straight forward.

so then the script that I am using only has to deal with one file at a time. The source code is:

Code: Select all

include("../inc_sql.php"); 
	
	set_time_limit(0);
	
	$litter  = array(' ', '-');

	$uploadDir = "../gallery/".$_GET['foo']."/";
	$filename = str_replace($litter, "_", $_FILES['Filedata']['name']);
	$uploadFile = $uploadDir . $filename;
	move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadFile);
	chmod($uploadFile, 0777);
	
	include("class.resize.php");
	$imgresize = new resize_img();
	$imgresize->sizelimit_x = 652;
	$imgresize->sizelimit_y = 394;
	$imgresize->keep_proportions = true;
	$imgresize->output = 'jpg';
	
	if( $imgresize->resize_image( $uploadFile ) === false )
	{
	}
	else
	{
	  $imgresize->save_resizedimage( $uploadDir, substr($filename, 0 , -4) );
	}
	
	$imgresize->destroy_resizedimage();
	
	$imgresize = new resize_img();
	$imgresize->sizelimit_x = 50;
	$imgresize->sizelimit_y = 50;
	$imgresize->keep_proportions = true;
	$imgresize->output = 'jpg';
	
	if( $imgresize->resize_image( $uploadFile ) === false )
	{
	}
	else
	{
	  $imgresize->save_resizedimage( $uploadDir.'tn/', substr($filename, 0 , -4) );
	}
	
	chmod($uploadDir.'tn/'.substr($filename, 0 , -4), 0777);
	
	$imgresize->destroy_resizedimage();
	
	mysql_select_db($database_dggb, $dggb);
						
	$query_tab2 = "SELECT * FROM `images` WHERE `album` = '".$_GET['foo']."' ";
	$tab2 = mysql_query($query_tab2, $dggb);
	$row_tab2 = mysql_fetch_assoc($tab2);
	$totalRows_tab2 = mysql_num_rows($tab2);
	$litter  = array(' ', '-');
	$query = " INSERT INTO `images` ( `album` , `order` , `src` , `caption` , `active` ) VALUES ( '".$_GET['foo']."' , '".($totalRows_tab2 + 1)."' , '".$filename."' , '' , '1' ) ";
	mysql_query($query, $dggb);
I have these images ordered in to albums using a Mysql database and references to the files. The last but of script is just for adding a record into this database.

I hope something in here helps or at least points you in a different direction.

It's by no means a complete solution though since it's not working yet. I havge just tried the JUpload applet mentioned in your thread and it crashed my browser twice so I'm not convinced that is the best route.
beinn
Forum Newbie
Posts: 8
Joined: Tue Aug 07, 2007 11:43 am

Post by beinn »

Hi Steve, thanks for the head up. I like the use of flash as an option. I started looking at it this afternoon before I had to put to one side. I will carry on with it and let you know how I get along. By the looks of it we are doing the same prockect. My client is a photographer, who is looking to batch load files that have been resized etc. One of the things I plann on looking at is adding watermark automatically to the images, don't know if you have thought about this.

will let you know how I get along.
Post Reply