I am getting an error when i try and rename a file I am taking in from a html form into a directory using the following code. I need to alter the file name to make it unique by concatenating the $studyId onto it. The error prints out the file correctly originalName/studyId.extension. I can move the files into the “videos” folder if I do no concatentation and just use $_FILES["sonogram"]["name"] as the second argument for move_uploaded_file there are examples on php.net that use this syntax where you choose what your going to name the uploaded file so I am assuming its something silly. I should mention I am on a windows system. Any help would be greatly appreciated
$pathParts = pathinfo($_FILES["sonogram"]["name"]);
$file = $pathParts['filename'] . '/'. strval($studyId) . '.'. $pathParts['extension'];
move_uploaded_file($_FILES["sonogram"]["tmp_name"],"videos/". $file);
By concatening ‘/’, you are telling Windows that it’s in another directory. So, the file is trying to be moved to, example, “videos/filename/studyId.mp4”. Which means the directory “filename” should exist. If you want to use another directory, use
mkdir, or, changed the slash to an underscore or some other character.