I am trying to upload multiple files using PHP via curl on the command line (For now, my PHP script is only able to upload one file at a time.) All files are of the same type. But each file belongs to different school and class.
For example, the user types the following on the command line:
curl –F “uploadedfile=@/home/michael/test” –F “school=diamond” –F “class=alpha” http://website.com/michael/upload.php
File name, school and class are specified by the user.
The expected outcome is the script is able to upload the file test to the alpha directory:
/michael/uploads/diamond/alpha
The PHP is:
<?php
$target_path = “uploads/”;
//I tried to add these 3 lines, but it doesn't work
$school = basename( $_FILES['uploadedfile']['school']);
$class = basename( $_FILES['uploadedfile']['class']);
$target_path = $target_path . $school . "/" . $class . "/" . basename( $_FILES['uploadedfile']['name']);
//$target_path = $target_path . basename( $_FILES[‘uploadedfile’][‘name’]);
if(move_uploaded_file($_FILES[‘uploadedfile’][‘tmp_name’], $target_path)) {
echo “The file”. basename( $_FILES[‘uploadedfile’][‘name’]. “ has been uploaded”;
} else {
echo “There was an error uploading the file, please try again!”;
}
?>
After reading the manual, I noticed that I can't do $_FILES['uploadedfile']['school']and ['class'].How could I modify my PHP script so that it can capture the school and class and upload the file to the class subdirectory?