Rank: Member
Groups: Member
Joined: 11/26/2008(UTC) Posts: 17
|
Hello I have almost none of PHP knowledge, can someone please give me the PHP code for this pseudocode so I can preserve folder structure on uploadsQuote: iterate through each file (i) { //This value is taken from the FileName_i POST field string fullPath //This value is pre-defined string galleryPath //The 'split' function splits a string into an array of substrings using //the specified delimiter ('\' in our case) array folderStructure = split(fullPath, "\") //The 'goToFolder' function changes the current working folder to the //specified one goToFolder(galleryPath) iterate through each element of folderStructure (j) { //The 'exists' function checks if the specified folder exists under the //current location if not exists(folderStructure[j]) { //The 'createFolder' function creates a subfolder createFolder(folderStructure[j]) } goToFolder(folderStructure[j]) } //The 'save' function saves the current file in the current working folder save(file[i]) }
Edited by user Tuesday, February 9, 2010 9:08:33 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member
Groups: Joined: 6/16/2009(UTC) Posts: 134
Was thanked: 8 time(s) in 8 post(s)
|
Hello! I've made small simple example of how to do this. The upload.php file contains all code you need to save received files with preserving folder structure. The index.php file contains the Image Uploader configuration settings to enable Upload Folder feature. The key options is AllowFolderUpload, IncludeSubfolders, ShowSubfolders. You can find it in the attached archive. |
|
|
|
|
Rank: Member
Groups: Member
Joined: 11/26/2008(UTC) Posts: 17
|
Almost done, only one little problem, the script is that is not creating folders properly yet, it does upload all files, but files inside a folder are created as "foldername\\filename1.jpg" "foldername\\filename2.jpg"
I mean the pictures inside a subfolder are renamed "foldername\\filename1.jpg"
|
|
|
|
Rank: Member
Groups: Member
Joined: 11/26/2008(UTC) Posts: 17
|
See image to better understanding.. 
|
|
|
|
Rank: Advanced Member
Groups: Joined: 6/16/2009(UTC) Posts: 134
Was thanked: 8 time(s) in 8 post(s)
|
Oh, I think we should use DIRECTORY_SEPARATOR constant as path delimiter. I've made the necessary changes and attached updated sample to this post. |
|
|
|
|
Rank: Member
Groups: Member
Joined: 11/26/2008(UTC) Posts: 17
|
Thanks! works like a charm now!!!
|
|
|
|
Rank: Member
Groups: Member
Joined: 11/26/2008(UTC) Posts: 17
|
Is there a way to specify that the created subfolders dont get owner permissions since its a mess to delete them I have to use this script:
<?php $old = umask(0000); chmod("foldername", 0777); umask($old); ?>
editing the "foldername" each time i want to delete a folder uploaded, since every folder is under the 99 99 group, is there a way to change the group owner on the upload
|
|
|
|
Rank: Advanced Member
Groups: Joined: 3/9/2008(UTC) Posts: 554
Was thanked: 1 time(s) in 1 post(s)
|
Hi, I hope the following code snippet helps you: Code:// Create directory if it not exists
if (!file_exists($absDirectoryName)) {
$old = umask(0000);
mkdir($absDirectoryName, 0777, TRUE);
umask($old);
}
Unfortunately we do not have appropriate soft ware to check it, so please let us know about your results. |
|
|
|
|
Rank: Member
Groups: Member
Joined: 11/26/2008(UTC) Posts: 17
|
Works excellent, now I can delete wichever folder or file any user upload without any problem, thanks
|
|
|
|
Rank: Advanced Member
Groups: Joined: 6/16/2009(UTC) Posts: 134
Was thanked: 8 time(s) in 8 post(s)
|
This is the same sample for ASP.NET on VB.NET. |
|
|
|
|
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.