php - How to upload file into different directory based on url token value -


this code html

    <form enctype="multipart/form-data" action="l.coursepage.php?id=<?php echo $id;?>"     method="post">     <input type="hidden" name="max_file_size" value="100000" /><br>     choose file upload: <input name="uploadedfile" type="file" /><br />     <input type="submit" value="upload file" name="upasg">     </form> 

this php code:

    if(isset($_post['upasg'])) {         //folder save in         $targetpath = $id."/download/assignment";          if (!is_dir($targetpath)){          mkdir($targetpath);          }         $targetpath = $targetpath . basename($_files['uploadedfile']['name']);         $_files['uploadedfile']['tmp_name'];         if ($_files['uploadedfile']['size'] < 2000) {             if (move_uploaded_file($_files['uploadedfile']['tmp_name'],$targetpath)){                 echo "the file ". basename($_files['uploadedfile']['name'])." has been uploaded.";             } else {                 echo "there error uploading file, please try again.";             }         } else {             echo "the file big";         }     }     ?> 

what i'm trying upload file different directory when pageid different. example: in /l.coursepage.php?id=1, file trying upload in page should save in 1/download/assignment path.

and error:

warning: mkdir(): no such file or directory in d:\xampp\htdocs\xampp\foundation\l.coursepage.php on line 148

warning: move_uploaded_file(ttt1234/download/assignment1.txt): failed open stream: no such file or directory in d:\xampp\htdocs\xampp\foundation\l.coursepage.php on line 153

warning: move_uploaded_file(): unable move 'd:\xampp\tmp\phpbf13.tmp' 'ttt1234/download/assignment1.txt' in d:\xampp\htdocs\xampp\foundation\l.coursepage.php on line 153 there error uploading file, please try again.

the error says php not recognize targetpath, because forget $ sign in mkdir(targetpath);

for uploadedfile index, in first code name="uploaded file" space.

these php errors quite explicit :d


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -