moosey_man1988 Posted May 28, 2015 Share Posted May 28, 2015 Hi There I'm pretty New to php im trying to creat an upload page that will store the file in the customers variable (Reference number) This is what im having trouble with $path = "uploads/".$customernumber."/".$dateFile.""; getting that second / to work.. here's the full code of what im trying to achieve (upload a file to a upload/$customernumber/date/test.txt) please bear in mind this is a php page called by another php page so there may be some variables missing $directory = is_dir($path); $dateFile= date('Y-m-d'); $path = "uploads/".$customernumber."/".$dateFile.""; $extension = end(explode(".", $_FILES["file"]["name"])); if ($_FILES["file"]["size"] > 2000000 ) { die ('please provide a smaller file size.' ); } if ( !( in_array($extension, $allowedExts))) { die('Please Provide a Different File Type.'); } if ($directory == false) { mkdir($path, 0777); } the upload page itself works but i just need to get the directories right. Quote Link to comment Share on other sites More sharing options...
maxxd Posted May 28, 2015 Share Posted May 28, 2015 Where are you setting $customernumber? Make sure you have error display turned on and see if the code is throwing any errors. You may also want to simply echo out $path and make sure you're looking where you think you're looking. Other thing, please be sure to use the code button [ <> ] in the text editor when posting code. It makes things easier to read. Quote Link to comment Share on other sites More sharing options...
Solution moosey_man1988 Posted May 28, 2015 Author Solution Share Posted May 28, 2015 Hey very sorry i fixed, the issue was i was trying to makdir 2 directories (face palm)! creates another variable with the first directory and then another with both and told the php script to mkdir the first directory THEN the second one, so all along it wasnt that line. Here's the result code: $directory = is_dir($path); $dateFile= date('Y-m-d'); $customerPath = "uploads/".$customernumber.""; $path = "uploads/".$customernumber."/".$dateFile.""; $extension = end(explode(".", $_FILES["file"]["name"])); if ($_FILES["file"]["size"] > 2000000 ) { die ('please provide a smaller file size.' ); } if ( !( in_array($extension, $allowedExts))) { die('Please Provide a Different File Type.'); } if ($directory == false) { mkdir($customerPath, 0777); mkdir($path, 0777); } if (in_array( $_FILES["file"]["type"], $AllowedMimeTypes) ) { $fileName=$_FILES["file"]["name"]; move_uploaded_file($_FILES["file"]["tmp_name"], "$path/" . $_FILES["file"]["name"]); } else { die ('Please Provide Another File Type'); } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.