php file uploading cannot retrieve the path












0















I am trying to upload photos in to folder uploads and its path to be recorded under photo in DB. This is my code:



$folder ="uploads";
$destFile = $folder . basename($_FILES["photo"]["name"]);
$sourdeFile = $_FILES["photo"]["tmp_name"];


if(move_uploaded_file($sourdeFile,$destFile)){
echo "File has been uploaded";
$photo = $destFile;
}else{
echo $_FILES['photo']['error'];
$photo = "images/default.png";
}


When I upload photos they successfully uploaded into folder but the problem is its path recorded as follow :



uploads42141402_1866830986743601_8538143552767524864_n.jpg


But to view photos in a page there should be next to uploads. So I tried to change my code as follow.



$folder = "uploads";


But it generates this error



Can anyone say how to fix this ?










share|improve this question

























  • You have the wrong slash should be /

    – rpm192
    Nov 15 '18 at 8:06













  • i did it too.But still same error

    – Nipun Tharuksha
    Nov 15 '18 at 8:07











  • have you given read-write permission to the upload folder? also, check the uploads folder should be inside carsale/controller folder

    – Sayed Mohd Ali
    Nov 15 '18 at 8:34













  • i did it too.Moved the folder into controller folder and change.but error is till same

    – Nipun Tharuksha
    Nov 15 '18 at 9:43
















0















I am trying to upload photos in to folder uploads and its path to be recorded under photo in DB. This is my code:



$folder ="uploads";
$destFile = $folder . basename($_FILES["photo"]["name"]);
$sourdeFile = $_FILES["photo"]["tmp_name"];


if(move_uploaded_file($sourdeFile,$destFile)){
echo "File has been uploaded";
$photo = $destFile;
}else{
echo $_FILES['photo']['error'];
$photo = "images/default.png";
}


When I upload photos they successfully uploaded into folder but the problem is its path recorded as follow :



uploads42141402_1866830986743601_8538143552767524864_n.jpg


But to view photos in a page there should be next to uploads. So I tried to change my code as follow.



$folder = "uploads";


But it generates this error



Can anyone say how to fix this ?










share|improve this question

























  • You have the wrong slash should be /

    – rpm192
    Nov 15 '18 at 8:06













  • i did it too.But still same error

    – Nipun Tharuksha
    Nov 15 '18 at 8:07











  • have you given read-write permission to the upload folder? also, check the uploads folder should be inside carsale/controller folder

    – Sayed Mohd Ali
    Nov 15 '18 at 8:34













  • i did it too.Moved the folder into controller folder and change.but error is till same

    – Nipun Tharuksha
    Nov 15 '18 at 9:43














0












0








0








I am trying to upload photos in to folder uploads and its path to be recorded under photo in DB. This is my code:



$folder ="uploads";
$destFile = $folder . basename($_FILES["photo"]["name"]);
$sourdeFile = $_FILES["photo"]["tmp_name"];


if(move_uploaded_file($sourdeFile,$destFile)){
echo "File has been uploaded";
$photo = $destFile;
}else{
echo $_FILES['photo']['error'];
$photo = "images/default.png";
}


When I upload photos they successfully uploaded into folder but the problem is its path recorded as follow :



uploads42141402_1866830986743601_8538143552767524864_n.jpg


But to view photos in a page there should be next to uploads. So I tried to change my code as follow.



$folder = "uploads";


But it generates this error



Can anyone say how to fix this ?










share|improve this question
















I am trying to upload photos in to folder uploads and its path to be recorded under photo in DB. This is my code:



$folder ="uploads";
$destFile = $folder . basename($_FILES["photo"]["name"]);
$sourdeFile = $_FILES["photo"]["tmp_name"];


if(move_uploaded_file($sourdeFile,$destFile)){
echo "File has been uploaded";
$photo = $destFile;
}else{
echo $_FILES['photo']['error'];
$photo = "images/default.png";
}


When I upload photos they successfully uploaded into folder but the problem is its path recorded as follow :



uploads42141402_1866830986743601_8538143552767524864_n.jpg


But to view photos in a page there should be next to uploads. So I tried to change my code as follow.



$folder = "uploads";


But it generates this error



Can anyone say how to fix this ?







php file file-upload






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 8:33









octano

208415




208415










asked Nov 15 '18 at 7:51









Nipun TharukshaNipun Tharuksha

62




62













  • You have the wrong slash should be /

    – rpm192
    Nov 15 '18 at 8:06













  • i did it too.But still same error

    – Nipun Tharuksha
    Nov 15 '18 at 8:07











  • have you given read-write permission to the upload folder? also, check the uploads folder should be inside carsale/controller folder

    – Sayed Mohd Ali
    Nov 15 '18 at 8:34













  • i did it too.Moved the folder into controller folder and change.but error is till same

    – Nipun Tharuksha
    Nov 15 '18 at 9:43



















  • You have the wrong slash should be /

    – rpm192
    Nov 15 '18 at 8:06













  • i did it too.But still same error

    – Nipun Tharuksha
    Nov 15 '18 at 8:07











  • have you given read-write permission to the upload folder? also, check the uploads folder should be inside carsale/controller folder

    – Sayed Mohd Ali
    Nov 15 '18 at 8:34













  • i did it too.Moved the folder into controller folder and change.but error is till same

    – Nipun Tharuksha
    Nov 15 '18 at 9:43

















You have the wrong slash should be /

– rpm192
Nov 15 '18 at 8:06







You have the wrong slash should be /

– rpm192
Nov 15 '18 at 8:06















i did it too.But still same error

– Nipun Tharuksha
Nov 15 '18 at 8:07





i did it too.But still same error

– Nipun Tharuksha
Nov 15 '18 at 8:07













have you given read-write permission to the upload folder? also, check the uploads folder should be inside carsale/controller folder

– Sayed Mohd Ali
Nov 15 '18 at 8:34







have you given read-write permission to the upload folder? also, check the uploads folder should be inside carsale/controller folder

– Sayed Mohd Ali
Nov 15 '18 at 8:34















i did it too.Moved the folder into controller folder and change.but error is till same

– Nipun Tharuksha
Nov 15 '18 at 9:43





i did it too.Moved the folder into controller folder and change.but error is till same

– Nipun Tharuksha
Nov 15 '18 at 9:43












2 Answers
2






active

oldest

votes


















0














How about



$folder ="uploads/";


I've tried and it works. Maybe $folder ="uploads" . DIRECTORY_SEPARATOR; will better than "/".






share|improve this answer


























  • no it dosent work

    – Nipun Tharuksha
    Nov 15 '18 at 8:05











  • Ahhh, I got why. How about this link

    – Van Tho
    Nov 15 '18 at 8:18





















0














For the error its looks uploads folder is not there or it not have permission



create a upload folder or try with absolute path



you can make use of dirname(__FILE__) or $_SERVER['DOCUMENT_ROOT'] for creating dynamic path






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314660%2fphp-file-uploading-cannot-retrieve-the-path%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    How about



    $folder ="uploads/";


    I've tried and it works. Maybe $folder ="uploads" . DIRECTORY_SEPARATOR; will better than "/".






    share|improve this answer


























    • no it dosent work

      – Nipun Tharuksha
      Nov 15 '18 at 8:05











    • Ahhh, I got why. How about this link

      – Van Tho
      Nov 15 '18 at 8:18


















    0














    How about



    $folder ="uploads/";


    I've tried and it works. Maybe $folder ="uploads" . DIRECTORY_SEPARATOR; will better than "/".






    share|improve this answer


























    • no it dosent work

      – Nipun Tharuksha
      Nov 15 '18 at 8:05











    • Ahhh, I got why. How about this link

      – Van Tho
      Nov 15 '18 at 8:18
















    0












    0








    0







    How about



    $folder ="uploads/";


    I've tried and it works. Maybe $folder ="uploads" . DIRECTORY_SEPARATOR; will better than "/".






    share|improve this answer















    How about



    $folder ="uploads/";


    I've tried and it works. Maybe $folder ="uploads" . DIRECTORY_SEPARATOR; will better than "/".







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 15 '18 at 8:05

























    answered Nov 15 '18 at 8:02









    Van ThoVan Tho

    846




    846













    • no it dosent work

      – Nipun Tharuksha
      Nov 15 '18 at 8:05











    • Ahhh, I got why. How about this link

      – Van Tho
      Nov 15 '18 at 8:18





















    • no it dosent work

      – Nipun Tharuksha
      Nov 15 '18 at 8:05











    • Ahhh, I got why. How about this link

      – Van Tho
      Nov 15 '18 at 8:18



















    no it dosent work

    – Nipun Tharuksha
    Nov 15 '18 at 8:05





    no it dosent work

    – Nipun Tharuksha
    Nov 15 '18 at 8:05













    Ahhh, I got why. How about this link

    – Van Tho
    Nov 15 '18 at 8:18







    Ahhh, I got why. How about this link

    – Van Tho
    Nov 15 '18 at 8:18















    0














    For the error its looks uploads folder is not there or it not have permission



    create a upload folder or try with absolute path



    you can make use of dirname(__FILE__) or $_SERVER['DOCUMENT_ROOT'] for creating dynamic path






    share|improve this answer






























      0














      For the error its looks uploads folder is not there or it not have permission



      create a upload folder or try with absolute path



      you can make use of dirname(__FILE__) or $_SERVER['DOCUMENT_ROOT'] for creating dynamic path






      share|improve this answer




























        0












        0








        0







        For the error its looks uploads folder is not there or it not have permission



        create a upload folder or try with absolute path



        you can make use of dirname(__FILE__) or $_SERVER['DOCUMENT_ROOT'] for creating dynamic path






        share|improve this answer















        For the error its looks uploads folder is not there or it not have permission



        create a upload folder or try with absolute path



        you can make use of dirname(__FILE__) or $_SERVER['DOCUMENT_ROOT'] for creating dynamic path







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 15 '18 at 10:43

























        answered Nov 15 '18 at 10:35









        Mahesh HegdeMahesh Hegde

        54859




        54859






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314660%2fphp-file-uploading-cannot-retrieve-the-path%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()