class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
$files = array();
foreach ($_FILES['my_field'] as $k => $l) {
foreach ($l as $i => $v) {
if (!array_key_exists($i, $files))
$files[$i] = array();
$files[$i][$k] = $v;
}
}
// now we can loop through $files, and feed each element to the class
foreach ($files as $file) {
//here i want to set set the name of the files :
$handle->file_new_name_body = "test";
//and i want to have for a multiple file upload i want for exemple :
//test1.pdf
//test2.pdf ..........
// we instanciate the class for each element of $file
$handle = new Upload($file);
// then we check if the file has been uploaded properly
// in its *temporary* location in the server (often, it is /tmp)
if ($handle->uploaded) {
// now, we start the upload 'process'. That is, to copy the uploaded file
// from its temporary location to the wanted location
$handle->Process("/home/lclprint/fichiers/");
//print($handle->file_dst_pathname);
// we check if everything went OK
if ($handle->processed) {
// everything was fine !
$content.='Vos fichiers ont été correctement transmis.';
//echo ' file uploaded with success';
} else {
// one error occured
$content.='Vos fichiers n\'ont pas été transmis.';
// echo ' file not uploaded to the wanted location';
}
} else {
// if we're here, the upload file failed for some reasons
// i.e. the server didn't receive the file
} elseif(isset($_POST['upFichier'])) {
$handle = new Upload($_FILES['my_field']);
if ($handle->uploaded) {
// yes, the file is on the server
// now, we start the upload 'process'. That is, to copy the uploaded file
// from its temporary location to the wanted location
// It could be something like $handle->Process('/home/www/my_uploads/');
$handle->Process("/home/lclprint/fichiers/");
// we check if everything went OK
if ($handle->processed) {
// everything was fine !
$content='Votre fichier à été correctement transféré.';
}
}
}
here is my code :
Bye