Welcome Guest Search | Active Topics

Add Reply New Topic

HOWTO: Preserve Folder Structure

Options
joanmjc
Posted: Monday, February 01, 2010 9:39:10 PM
joanmjc's avatar
Rank: Member
Groups: Member

Joined: 11/27/2008
Posts: 17
Points: 51
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 uploads

Quote:

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])
}
andreym
Posted: Thursday, February 04, 2010 4:09:45 AM
Rank: Member
Groups: Member

Joined: 6/16/2009
Posts: 24
Points: 72
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.

File Attachment(s):
folder_structure.zip (2,101kb) downloaded 2 time(s).


joanmjc
Posted: Thursday, February 04, 2010 9:28:27 AM
joanmjc's avatar
Rank: Member
Groups: Member

Joined: 11/27/2008
Posts: 17
Points: 51
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"
joanmjc
Posted: Thursday, February 04, 2010 9:31:00 AM
joanmjc's avatar
Rank: Member
Groups: Member

Joined: 11/27/2008
Posts: 17
Points: 51
See image to better understanding..

andreym
Posted: Thursday, February 04, 2010 9:35:07 PM
Rank: Member
Groups: Member

Joined: 6/16/2009
Posts: 24
Points: 72
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.

File Attachment(s):
folder_structure.zip (2,101kb) downloaded 8 time(s).


joanmjc
Posted: Friday, February 05, 2010 4:12:18 AM
joanmjc's avatar
Rank: Member
Groups: Member

Joined: 11/27/2008
Posts: 17
Points: 51
Thanks! works like a charm now!!!
joanmjc
Posted: Friday, February 05, 2010 5:03:58 AM
joanmjc's avatar
Rank: Member
Groups: Member

Joined: 11/27/2008
Posts: 17
Points: 51
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
Tamila
Posted: Monday, February 08, 2010 11:02:28 AM
Rank: Advanced Member
Groups: Administration , Member

Joined: 3/10/2008
Posts: 425
Points: 1,178
Hi,

I hope the following code snippet helps you:
// 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.


Best regards,
Tamila Ashrafova

Aurigma Support Team
joanmjc
Posted: Wednesday, February 10, 2010 3:20:01 AM
joanmjc's avatar
Rank: Member
Groups: Member

Joined: 11/27/2008
Posts: 17
Points: 51
Works excellent, now I can delete wichever folder or file any user upload without any problem, thanks
Users browsing this topic
Guest

Add Reply New 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.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Yet Another Forum.net version 1.9.1.6 running under Cuyahoga.
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.