0

Im trying to add file uploading to my app but for some reason the php script doesnt move the file. I'm using angularjs and the code works fine but in the script it doesn't move/upload the file as it's supposed. Below is the code I have

<?php
    $name = $_FILES['filee']['name'];
    $tmp_name = $_FILES['filee']['tmp_name'];
    $loc = '/media/img/';

    if(move_uploaded_file($_FILES['filee']['name'], $loc)){
        echo $_FILES['filee']['tmp_name'].$loc.$name;
    }
?>

I don't see whats wrong with the script!!

1 Answer 1

1

you need to use tmp_name in the first argument of move_uploaded_file() function as below

<?php
    $name = $_FILES['filee']['name'];
    $tmp_name = $_FILES['filee']['tmp_name'];
    $loc = 'media/img/'.$name; //desitination needs file name also
    if(!is_dir('media/img/') && !file_exists('media/img') ) {
      mkdir('media/img',0777,true);
    }
    if(move_uploaded_file($_FILES['filee']['tmp_name'], $loc)){
        echo $_FILES['filee']['tmp_name'].$loc.$name;
    }
?>

also make sure form has enctype attribute

Sign up to request clarification or add additional context in comments.

9 Comments

I used to tmp_name value but it still didnt work, i changed it to name to test.
add name at the end of $loc as i have set because destination should have file name in it and check form has enctype="multipart/form-data" attribute
That didnt seem to work for me, could there be something else?
it you are using linux, there should be directory write permission, so use chmod to change upload directory permission to 777
I'm using an online/cloud based IDE maybe thats the problem? as far as uploading files? Its called koding.com
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.