SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)

    Question $_FILES path and image name as a string

    $_FILES path and image name as a string.

    Can this be done from a form? If so, how?

    Sorry for the very short question, I've got to walk the dog

    spence
    "Don't you just love it when you solve a programming bug only to create another."

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    well put the dog down and explain yourself properly!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    ok.

    Once an image file (jpeg) has been selected to be uploaded can the path and the filename be converted to a string?

    So the user selects a file in "c:/my photos/me.jpg" for example, through the form.

    Then onto the next page, to make sure the user has selected the correct path, etc... I was after displaying the path and filename only.
    "Don't you just love it when you solve a programming bug only to create another."

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    I am pretty sure you cant get the full path of the users selected folder as it poses a security risk.

    I wonder if you could use javascript to grab it using DOM...?

    hmmm, some testing required....
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    ok, well it appears you can.....
    PHP Code:
    <script type="text/javascript">

        function getValue() {
            
            var textSet = document.testForm.uploadFile.value;
            alert(textSet);
        }

    </script>
    <?php

    echo '<pre>';
    print_r($_FILES);
    echo 
    '</pre>';

    ?>
    <form name="testForm" id="testForm" action="" method="post" enctype="multipart/form-data">
    <input type="file" name="uploadFile"><br />
    <input type="submit" name="submit" onClick="getValue();">
    </form>
    Returns an alert with the path in it..... cool
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Ok so this got me thinking....
    PHP Code:
    <script type="text/javascript">

        function getValue() {
            
            var textSet = document.testForm.uploadFile.value;
            document.testForm.testFile.value = textSet;
        }

    </script>
    <?php

    echo '<pre>';
    print_r($_FILES);
    print_r($_POST);
    echo 
    '</pre>';

    ?>
    <form name="testForm" id="testForm" action="" method="post" enctype="multipart/form-data">
    <input type="file" name="uploadFile" onClick="getValue();"><br />
    <input type="hidden" name="testFile" >

    <input type="submit" name="submit">
    </form>
    Puts the path into a hidden field onClick of the file input. this then gets sent through the POST array.
    You would need to run stripslashes on the value as php add them automatically
    C:\docs\spike
    becomes
    C:\\docs\\spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Thankx Spike.

    I wouldn't have thought of using javascript.

    spence
    "Don't you just love it when you solve a programming bug only to create another."

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    I wouldnt if i hadn't been hamering DOM for a project I am currently working on
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Lucky me, you were
    "Don't you just love it when you solve a programming bug only to create another."


Bookmarks

Posting Permissions

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