0

my code keeps on saying that the folder does not exist though it should be checked by the mkdir function..it creates the folder but does not go through the uploading process.. and displays the error on the couldnt find the folder.. is the algorithm correct? please help.. Your advice will help! :)

here is the code..

if(!(file_exists($target_path)))
{
    if(!mkdir($target_path, 0777, TRUE))
    {
        die ("could not create the folder on mkdir");
    }
    //in this line the error occurs..printing what is below..//
    die ("could not find folder on file exists");
}
else
{
    umask($target_path);
    ...
}
4
  • Can you quote the exact error messages and which lines they occur on? Commented Jan 8, 2012 at 13:15
  • @Pekka I already did.. please have a look.. thank you.. :D Commented Jan 8, 2012 at 13:18
  • thanks for the edit @hakre hehe.. :D dont know how to say it.. Commented Jan 8, 2012 at 13:22
  • @SimonCode: I edited your question again and reduced the code to the part that plays the role here. Probably you now better see where your problem with this is. The cause of your problem is that you write many if/else clauses into each other which makes your code complex. Create functions instead that do part of the work, then invoke the functions to do the job. Commented Jan 8, 2012 at 13:28

3 Answers 3

1

file_exists() routine requires the complete path to file like

/var/www/uploads/file1.c

so the

file_exists($target_path); 

call is ok . but second call to make directory, ie,

mkdir()

is requiring an directory , not an path to an file ie, it require /var/www/upload part only . so you can remove the basename from path name and apply it to mkdir function()

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

Comments

1

try..

if(file_exists($target_path) && is_dir($target_path)){ //rest of the code... }

instead of...

if(!(file_exists($target_path))){

}

Hope this will do something for you...

...............................

one thing more... i think the problem is with if(!(file_exists($target_path))){} Statement,

THIS SHOULD BE... if(!file_exists($target_path)){}

Comments

1

during the file upload process, your file saving path in move_uploaded_file() function may be creating problem. I am saying may be because your given code is not clear enough to me. Second parameter of move_uploaded_file() is the destination where first parameter is the file name. please check the value of $target_path, it may solve your problem. thank you.

Comments

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.