English
00:00:00


Php handler for uploading multiple images to the server

The slider script  |  Zip unpacker  |  The script hit counter  |  Feedback script  |  Click to enlarge

AVL advertising materials rotator  |  How much is currently on the site.  |  Online program code highlighting

The script for the highlighting of program code  |  Form for uploading multiple images

Two examples of form code for uploading multiple images  |  Php handler for uploading multiple images to the server

Your comment or question

In this material, I offer the code of my script " Php load handler
several images to the server
" and a short description of its operation.
And try to upload your images using my script.
Below the page is the code of this script.

Script retrieves data from the form and the form code from the link.

The second version of the form code.

Each form input passes data with its own variable, since the array is only
needed for multiple downloads with a single input with the multiple attribute,
as in parentheses (<input type="file" name="file[]" multiple>).

Script it has several types of checks for the reason for running the script
(against hacking attempts):
1) checking the address - where the script was launched from.
2) Captcha-protection not only from bots, but also attempts to circumvent our form.
3) from attempts-filling out the form, enter the program code.
4) Function "is_uploaded_file", checking whether the file was actually uploaded
using the "post" method, so that you can't copy it using our script,
some file that is not allowed to view, from your server.

Checks the file size - if it is larger than allowed, the file is skipped,
and the script continues to work.
Checking the file type.

When loading , the script creates a unique file name, for which it
is necessary translates the initial name from Cyrillic to Latin (the translate
function, not the author functions, but in this case it is very useful and I use it).
The resulting script adds a unique code and name
the image becomes unique.
Next, the script saves the file to your folder by copying it from
the temporary one. And so on the cycle, until all files are uploaded.

Try the script " Php handler for uploading multiple images to the server "
while you are working, upload your images to the server and you will see them on
this page.

Your images will be saved for five minutes and will only be visible by your ip which
you had at the time of loading (there are no such restrictions in the script itself).
That is , if your ip changes with the page update, then your images will change to
you won't see the page.

Image  Open the upload form

Here is the code itself:

// Php handler for uploading multiple images to the server 

< ?php

// Checking the address - where the script was launched from.

$otkuda getenv("HTTP_REFERER");
if (!
stristr($otkuda$_SERVER["HTTP_HOST"])) {
   
header("Location: /");
exit();
}

// Errpusk function for easy error output!

function errpusk($errors) {
if (!empty(
$errors)) {
   global 
$otkuda;
   
$errormass array_shift($errors);
   if (!
stristr($otkuda"?")) header("Location: $otkuda?commerr=" $errormass);
   else 
header("Location: $otkuda&commerr=" $errormass);
   exit();
   }
}
  
// Filter from attempts - fill in the form, enter the program code.
// Use for any numbers, names, and strings passed by the form!

function zensuraString($var)
{
$var stripslashes($var);
$var strip_tags($var);
$var htmlspecialchars($varENT_NOQUOTES"UTF-8");
$var trim($var);
return 
$var;
}

// The transition to the Latin alphabet!
function translit($var)
{
    
$converter = array(
        
'а' => 'a',    'б' => 'b',    'в' => 'v',    'г' => 'g',    'д' => 'd',
        
'е' => 'e',    'ё' => 'e',    'ж' => 'zh',   'з' => 'z',    'и' => 'i',
        
'й' => 'y',    'к' => 'k',    'л' => 'l',    'м' => 'm',    'н' => 'n',
        
'о' => 'o',    'п' => 'p',    'р' => 'r',    'с' => 's',    'т' => 't',
        
'у' => 'u',    'ф' => 'f',    'х' => 'h',    'ц' => 'c',    'ч' => 'ch',
        
'ш' => 'sh',   'щ' => 'sch',  'ь' => '',     'ы' => 'y',    'ъ' => '',
        
'э' => 'e',    'ю' => 'yu',   'я' => 'ya',
 
        
'А' => 'A',    'Б' => 'B',    'В' => 'V',   'Г' => 'G',    'Д' => 'D',
        
'Е' => 'E',    'Ё' => 'E',    'Ж' => 'Zh',  'З' => 'Z',    'И' => 'I',
        
'Й' => 'Y',    'К' => 'K',    'Л' => 'L',    'М' => 'M',    'Н' => 'N',
        
'О' => 'O',    'П' => 'P',    'Р' => 'R',    'С' => 'S',    'Т' => 'T',
        
'У' => 'U',    'Ф' => 'F',    'Х' => 'H',    'Ц' => 'C',    'Ч' => 'Ch',
        
'Ш' => 'Sh',   'Щ' => 'Sch',  'Ь' => '',     'Ы' => 'Y',    'Ъ' => '',
        
'Э' => 'E',    'Ю' => 'Yu',   'Я' => 'Ya',
    );
 
    
$var strtr($var$converter);
    return 
$var;
}

if (isset(
$_POST["co_reset"])) {  // canceling a download
header("Location: $otkuda");
exit();
}

if (isset(
$_POST["neskf_subm"])) {

// каптча

$slogaem_kaptch zensuraString($_POST["slogaem_kaptch"]);
$slogaem_kaptch preg_replace("/[^0-9]/"""$slogaem_kaptch);

$znak_kaptch zensuraString($_POST["znak_kaptch"]);
$znak_kaptch preg_replace("/[^0-9]/"""$znak_kaptch);

$zadan_kaptch zensuraString($_POST["zadan_kaptch"]);
$zadan_kaptch preg_replace("/[^0-9]/"""$zadan_kaptch);

$otvet_kaptch zensuraString($_POST["otvet_kaptch"]);
$otvet_kaptch preg_replace("/[^0-9]/"""$otvet_kaptch);
$errors = array();

switch (
$slogaem_kaptch)
{
        case 
$tslog 43; break;
        case 
$tslog 42; break;
        case 
$tslog 47; break;
        case 
$tslog 51; break;
        case 
$tslog 59; break;
        case 
$tslog 69; break;
        case 
$tslog 65; break;

   
if (
$znak_kaptch == 0) {
   if (
$otvet_kaptch != $tslog $zadan_kaptch) {
      
$errors[] = 23;
      
$errormass errpusk($errors);
   }
}
if (
$znak_kaptch == 1) {
   if (
$otvet_kaptch != $tslog $zadan_kaptch) {
      
$errors[] = 23;
      
$errormass errpusk($errors);
   }
}

if(isset(
$_FILES["imgcp_1"])) {
$dirimages $_SERVER["DOCUMENT_ROOT"] . "/upload/"// Ваша папка!
$k 1;
$maximgsize 1024 500;

$imgblockname = array();

while (isset(
$_FILES["imgcp_" $k])) {
    
$imgcp "imgcp_" $k;
    
$upfile      $_FILES[$imgcp]["tmp_name"];
    
$upfile_name $_FILES[$imgcp]["name"];
    
$upfile_size $_FILES[$imgcp]["size"];
    
$upfile_type $_FILES[$imgcp]["type"];
    
$error_code  $_FILES[$imgcp]["error"];
    
     if (
$upfile_size $maximgsize) {
    
$k++;
    continue;
    }

// Stop the script if this file was not loaded

    
if (is_uploaded_file($_FILES[$imgcp]["tmp_name"])) {
// если ошибок нет
    
if($error_code == 0) {
    switch(
$upfile_type) {
    case 
"image/pjpeg":
    case 
"image/jpeg"$ext "jpg"; break;
    case 
"image/gif"$ext "gif"; break;
    case 
"image/png"$ext "png"; break;
    case 
"image/tiff"$ext "tif"; break;
    default: 
$ext ""; break;
    }
    
    if ((
$ext) and ($ext != "")) {
    
$upfile_name translit($upfile_name);
    
$upfile_name strtolower(preg_replace("/[^A-Za-z0-9._]/"""$upfile_name));
    
$indivimg uniqid();
    
$arrupfilename explode("."$upfile_name);
    
$upfile_n $arrupfilename[0];
     
$imagename $upfile_n $k $indivimg "." $ext;
     
$upfile_name $dirimages $imagename;

     
copy($upfile$upfile_name);
     
     
$imgblockname[] = $imagename// Array of names of uploaded files to write to the database. 
    
     
$k++;
    } else {
    
$errors[] = 24;
    
$errormass errpusk($errors);
    }
     
    } else {
    
$errors[] = 25;
    
$errormass errpusk($errors);
    }
    } else {
    
$errors[] = 26;
    
$errormass errpusk($errors);
    }
}

header("Location: $otkuda"); // Returns to the page if the result is positive!

} else {
    
header("Location: /");
    exit();
}

} else {
    
header("Location: /");
    exit();
}

? >

The script is free and can be installed on any number of your sites,
but you can only distribute with the presence of a link to this site from the site
distributions.    good Luck! Alexey.



The slider script  |  Zip unpacker  |  The script hit counter  |  Feedback script  |  Click to enlarge

AVL advertising materials rotator  |  How much is currently on the site.  |  Online program code highlighting

The script for the highlighting of program code  |  Form for uploading multiple images

Two examples of form code for uploading multiple images  |  Php handler for uploading multiple images to the server

Your comment or question

If you insert our link to your site at the address you wrote in the
comments, then your address will also become a link!