• Ok I’ve searched around a bit and haven’t found anything yet that will suite my needs. What I’m looking for is a way so that when I upload images or such I can create a sub-folder into the upload dir to upload those files to.
    Or even better yet when I upload an image for say article “Test” a folder is created called “test” and my images for that article are put there. The reason I ask for a feature to at least create sub-folders to upload to is because I’ll be using WP as a CMS and article management so we’ll be uploading a lot of images and such so it’d make it a lot easier to have them in folders instead of thrown all into one folder.
    Does anyone have any suggestions?
    -WoodiE

Viewing 1 replies (of 1 total)
  • There is something called a mkdir() command in PHP but to use it, you have to be the owner of files, that is, you cannot use it on a shared server or when PHP is running in safe mode. Hence, its better to use PHP’s FTP function to create the directory and then move the file uploaded there using FTP (because PHP’s move property will not work in safe mode or on a shared server). The code is as follows:
    <?php
    // create directory through FTP connection
    function FtpMkdir($path, $newDir) {
    $server='ftp.yourserver.com'; // ftp server
    $connection = ftp_connect($server); // connection

    // login to ftp server
    $user = "me";
    $pass = "password";
    $result = ftp_login($connection, $user, $pass);
    // check if connection was made
    if ((!$connection) || (!$result)) {
    return false;
    exit();
    } else {
    ftp_chdir($connection, $path); // go to destination dir
    if(ftp_mkdir($connection,$newDir)) { // create directory
    return $newDir;
    } else {
    return false;
    }
    ftp_close($conn_id); // close connection
    }
    }
    ?>
    A similar code can be written for moving the uploaded file though some values are needed from upload.php to do so. I guess, hacking upload.php would be the best option. May be somebody will do the dirty work or I may do it sometime late next month (since I am down with school work now)…
    Abhishek.

Viewing 1 replies (of 1 total)
  • The topic ‘Upload to sub-folders…’ is closed to new replies.