Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php file upload problem

Options
  • 17-11-2009 12:08am
    #1
    Registered Users 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 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 Posts: 21 prometheos


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


  • Registered Users Posts: 6,509 ✭✭✭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 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 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 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 Posts: 9,579 ✭✭✭Webmonkey


    What has changed. You sure file uploads are enabled:

    file_uploads = on


  • Registered Users 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