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é.';
}
}
}
Iam using your class for multiple files upload.
I want to set the file name in the same that i submit my form.
I have a table (variable+php).
I dont want to use the file name but a name that i have creat before in php.
Can i do that thanks
So for instance, you can do:
But be careful to escape the field first, otherwise it is a big security risk!
For example i create ma form this way :
'; print($form);
I want for example have :
for Table=5
5 files uploaded, named :
MyName1, MyName2, MyName3, MyName4, MyName5
How can I set the extension file to let where lick she is in in the original file?
Thanks
Happy New Year
For multiple uploads, see the part called "What about multiple uploads?" in the FAQ.
here is my code :
Bye
With something like: