There is a form with 3 inputs, 2 text fields and a uploaded file. When the form is submitted the action is this uploader.php script. My question, is there a way to validate the upload in the first if on the uploaded file so I only need one if/else block?
Also how do I attach the time to the file name? NOw it is attaching to the "csv.txt"
.txt extension. This is an internal form for doing a conversion so I'm not worried about security as user input and errors getting the file uploaded.
thanks,
ini_set("display_errors",1);
ini_set("memory_limit",'640M');
ini_set("max_execution",120);
ini_set("file_uploads",1);
$time=time();
$target_path = "file_uploads/";
// Add the original filename to our target path.
//Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if (filter_has_var(INPUT_POST, 'cart_id')&& filter_has_var(INPUT_POST, 'bu')){
$cart_id = $_POST["cart_id"];
$bu = $_POST["bu"];
echo $cart_id;
echo $bu;
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path.$time)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file,
please try again. The file must be a csv file.";
}
}else{
echo "You are missing the cart_id or bu.";
}