• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Upload Whole Directory in PHP

mykel

Weaksauce
Joined
Jul 9, 2004
Messages
76
I'm aware of the typical tutorials that you can find via google that will allow you to upload one file at a time.
HTML:
<form enctype="multipart/form-data" action="upload.php" method="post">
	Upload: <input name="userfile" type="file" />
	<input type="submit" value="Upload File" />
</form>

And then retrieving it with an upload.php file that has:

PHP:
<?php
$uploadDir = '/var/www/uploads/';
$uploadFile = $uploadDir . $_FILES['userfile']['name'];
print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadFile))
{
	print "File is valid, and was successfully uploaded. ";
	print "Here's some more debugging info:\n";
	print_r($_FILES);
}
else
{
	print "Possible file upload attack!  Here's some debugging info:\n";
	print_r($_FILES);
}
print "</pre>";
?>
SOURCE: http://www.netspade.com/articles/php/uploading.xml

But how would I go about uploading a whole directory? I want to be able to select a directory and then PHP will chug away at adding all the files in that directory to a directory on the server. I have been unable to find any documentation on the web to help with this.

Thanks in advance!
 
I don't think it's a limitation of PHP as much as a limitation of the client being able to choose a directory. With the default windows browse dialog, I don't think it's possible. There may be some javascript or some other plugin/tool you could use for the client side allowing users to pick a directory. None come to mind though.

I think it would be coolest if the client could zip the dir and then send it in one file, but then you have problems with some clients not having zip capabilities.

Or, I suppose it would be possible to write some kind of a javascript that asks you what dir to upload, and then it automatically uploads each file in the dir one at a time. That might be the best approach. Comments?
 
Well, the purpose of this is to upload pictures to a specified gallery when I'm on the road. That way I'd be able to show my relatives, friends, and fans my pictures even when I'm not at home.

The zip idea is interesting, though. It might be possible for me to do such a thing since I will be the only user of the upload capabilities. I assume you mean I would zip a bunch of files and upload the zip to have the server decompress the files to a directory. Zipping it would help on the upload time too (if I had RAW's and such).

I suppose I could investigate this process and implement it in the mean time if I can't find an alternative. Thank you for this interesting concept! :)
 
mykel said:
Well, the purpose of this is to upload pictures to a specified gallery when I'm on the road. That way I'd be able to show my relatives, friends, and fans my pictures even when I'm not at home.

The zip idea is interesting, though. It might be possible for me to do such a thing since I will be the only user of the upload capabilities. I assume you mean I would zip a bunch of files and upload the zip to have the server decompress the files to a directory. Zipping it would help on the upload time too (if I had RAW's and such).

I suppose I could investigate this process and implement it in the mean time if I can't find an alternative. Thank you for this interesting concept! :)

Sorry, having a hard time understanding...

Edit: Nevermind... wierd... all the vowels in your post were exclamation points until after I posted this post. Now I can read it.
 
Glad I could help :)
Yeah zipping would be great. There might be a PHP function to unzip, and if not you could use PHP to execute a shell command to unzip uzing gunzip or something. I don't think zipping images really saves much space. In my experience, it's pennies on the dollar and the only good part about it is that they are all in one file. But I could be wrong, maybe there's some new compression technology that really lowers the file size.
 
You are correct. JPG's would not yield much of a difference. However, PNG/TIF/RAW/BMP should show a pretty fair change in size when zipped.

There is a ton of information on zip read functions at http://us2.php.net/zip. There's even a fellow in the comments section that provides an unzip function.
 
You could give the form several file inputs and pull them from an array. Or just get an FTP cliepnt and drop the directory that way.

mykel said:
You are correct. JPG's would not yield much of a difference. However, PNG/TIF/RAW/BMP should show a pretty fair change in size when zipped.

There is a ton of information on zip read functions at http://us2.php.net/zip. There's even a fellow in the comments section that provides an unzip function.

PNG images are compressed, so there would be no gain from zipping them.
 
Back
Top