Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

php file upload problem

  • 17-11-2009 12:08AM
    #1
    Registered Users, Registered Users 2 Posts: 21


    hi,
    im trying to get a file to upload to an images folder in php and it was working a while ago but i overwrote the file by accident and know cant remember what i had as i hadn't worked on it in a while. can anyone help me?

    i have the usual in the php file containing the entire form:
    [php]
    <input name="uploadedfile" type="file" size="40" />
    [/php]and then i have this in the uploaded php file ( i know its basic at the moment but i'm just trying to get it uploading again before i add more specific formats and sizes etc):
    [php]
    $target_path = "images/";
    $target_path = $target_path . basename( $_FILES);
    copy($_FILES, "images/" . $_FILES);
    [/php]can anybody tell me what's wrong? ive been staring at this for about 2hours now, so it's probably something stupid:mad:
    thanks guyz


Comments

  • Registered Users, Registered Users 2 Posts: 379 ✭✭TheWaterboy


    I think your $target_path is wrong

    I would assume that it needs to be something similar the following:

    $target_path = "/home/httpd/html/images/"


  • Closed Accounts Posts: 263 ✭✭HandWS LTD


    Yep...looks like its the target path. You need to put the full path in "$target_path =" depending on if it is in the root folder or not. Either just use "/images/" or the full path. I don't know what the full path is so i can't do anymore.


  • Registered Users, Registered Users 2 Posts: 21 prometheos


    hey,
    thanks for the replies:) ill give that a go now :)
    cheers for the help


  • Registered Users, Registered Users 2 Posts: 6,753 ✭✭✭daymobrew


    I don't think that the $target_path needs to be an absolute dir, though I suggest using the move_uploaded_file function as it is specifically for moving the uploaded file to its final destination.

    I suggest you create a test script and print out the values of the $_FILES array (var_dump is handy for this).
    [PHP]<pre>
    <?php
    var_dump( $_FILES );
    ?>
    </pre>
    [/PHP]
    The data in $_FILES may be different from what you expect e.g. $_FILES'uploadedfile'] may not need to have basename() applied to it (you apply it on one line but not the next).


  • Registered Users, Registered Users 2 Posts: 21 prometheos


    ok i now have
    [PHP]
    $target_path ="./images/";
    $target_path = $target_path . $_FILES;
    move_uploaded_file($_FILES, $target_path);
    [/PHP]

    i tried target_path with an absolute path and it didn't work.

    this is the result of the var dump of $_FILES and i got

    'array(0) {
    }'
    does this mean that the upload isnt going into temp? why would this be?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    From that it looks like you not even uploading a file properly? The $_FILE array should contain something at least.

    What's your form like for uploading. You sure your form tag contains multipart/form-data and using post.


  • Registered Users, Registered Users 2 Posts: 21 prometheos


    Webmonkey wrote: »
    From that it looks like you not even uploading a file properly? The $_FILE array should contain something at least.

    What's your form like for uploading. You sure your form tag contains multipart/form-data and using post.

    yeah, it has that at the top
    [PHP]<form enctype="multipart/form-data" method="POST" action="ordered.php">
    [/PHP]

    could it be because the upload_tmp_dir in php.ini isn't set?


  • Closed Accounts Posts: 263 ✭✭HandWS LTD


    No show us a bit more of the code so we can help. Or is that it?


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    What has changed. You sure file uploads are enabled:

    file_uploads = on


  • Registered Users, Registered Users 2 Posts: 21 prometheos


    Webmonkey wrote: »
    What has changed. You sure file uploads are enabled:

    file_uploads = on

    yeah its definitely on...
    i think i know what the problem is now... im trying to do it within facebook...
    it works if i do it outside facebook but not inside :mad:
    hmm....
    thanks for the help by the way :)
    any1 know a way around this ?


  • Advertisement
Advertisement
Advertisement