Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2006
    Location
    Bristol, UK
    Posts
    147
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Upload to different directories

    hi guys..

    I have an upload script on my site, for users to upload images to the gallery...
    PHP Code:
    <?php

    $uploaddir
    ="gallery";
    $uploaddirl="largegallery";

    if (
    is_uploaded_file($_FILES['file']['tmp_name']))
    {
    move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
    move_uploaded_file($_FILES['file']['tmp_name'],$uploaddirl.'/'.$_FILES['file']['name']);
    }
    print 
    "Image Uploaded Successfully"

    ?>
    I have 3 gallerys and each have 2 directories. The above script upoads to both gallery and largegallery. Or so it should lol

    What im after is on the form to have a drop down list that says select gallery to upload the image to....

    and then whichever option the user selects it will upload the image to the 2 directories relevent to that gallery.

    Is this possible?

    Thanks in advance

    Jon

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,632
    Thanks
    0
    Thanked 649 Times in 639 Posts
    If you give the form fields names of uploaddir and uploaddirl and are using method="post" then the fields will be available to the script as $_POST['uploaddir'] and $_POST['uploaddirl'] so you can then use those fields in your code to determine the directory (after validating their contents to make usre someone hasn't hacked your form in an attempt to use the fields for something else).
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Regular Coder
    Join Date
    May 2006
    Location
    Bristol, UK
    Posts
    147
    Thanks
    6
    Thanked 2 Times in 2 Posts
    i have just checked that script and it doesent work

    well it does, but it only uploads to $uploaddir and not to u$uploaddirl

    This is my form:

    Code:
    <form action="upload.php" method="post" enctype="multipart/form-data">
    	<div id="form">
    		<label class="boldital" for="file">Image:</label>
    		<input type="file" name="file" id="file">
    		<br>
    		<br>
    		<input type="submit" id="upload" name="upload" value="Upload">
    	</div>
    My galleries are as follows:

    Pool - pool_gallery
    ------ pool_largegallery

    Skating - skating_gallery
    ----------skating_gallerylarge

    Random - gallery
    ----------gallerylarge


    Thats it basically, i think i understand tha basics of what you mean, but i may be wrong and actually understand none of it!! lol

    i know i will need to put an option in the form to select the gallery name, then set the option to the variable that contains that relevent gallery name?

    Am i on the right track?

    thanks again

    jon

  • #4
    Regular Coder
    Join Date
    May 2006
    Location
    Bristol, UK
    Posts
    147
    Thanks
    6
    Thanked 2 Times in 2 Posts
    anyone got any ideas?

    the only idea i can think of is writing 3 different scripts maybe? but then how do i change the form action depending on option selected.??
    "You only live once, play it right, and once is enough" - me :)
    "When i die only god can take my soul" - me again! :P


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •