Калфа
Мнения: (20)
|
Искам да направя някаква форма за качване на файлове, които прави проверка за разширение и големина на файла, но искам при всеки качен файл да му се сменя името, без значение дали качвам файл с едно и също име.Нещо като това да е:
CODE1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| <?php
// Configuration - Your Options
$allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.
$max_filesize = 524288;//Maximum filesize in BYTES (currently 0.5MB).
$upload_path = '/files/';//The place the files will be uploaded to (currently a 'files' directory).
$filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);//Get the extension from the filename.
// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
// We'll start handling the upload in the next step
?> |
Само че да вкарам в него и това:
CODE1
2
3
4
5
6
7
8
9
10
11
12
13
| $file = "data.txt";//moje da promenish imeto na kakvoto iskash stiga da e sustoto s tova na faila ;)
$filesize = filesize($file);
$fp = fopen($file,"r");
$info=fread($fp,$filesize);
fclose($fp);
$broi = explode("|",$info);
$filename = "$file1$broi[0]"; // eto promenlivata ime ve4e e imgstoinostta
$uveli4eno = $broi[0] + 1;
$fo = fopen($file,"w");
fwrite($fo, $uveli4eno . "|");
fclose($fo); |
Пробвах да го направя така:
CODE1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| <?php
// Configuration - Your Options
$allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.
$max_filesize = 524288; //Maximum filesize in BYTES (currently 0.5MB).
$upload_path = '/files/'; //The place the files will be uploaded to (currently a 'files' directory).
$file1 = $_FILES['userfile']['name']; //Get the name of the file (including file extension).
$file = "data.txt";//moje da promenish imeto na kakvoto iskash stiga da e sustoto s tova na faila ;)
$filesize = filesize($file);
$fp = fopen($file,"r");
$info=fread($fp,$filesize);
fclose($fp);
$broi = explode("|",$info);
$filename = "$file1$broi[0]"; // eto promenlivata ime ve4e e imgstoinostta
$uveli4eno = $broi[0] + 1;
$fo = fopen($file,"w");
fwrite($fo, $uveli4eno . "|");
fclose($fo);
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
// We'll start handling the upload in the next step
?> |
Само, че като се опитам да кача някой файл изобщо не се качва нищо в папката където съм му задал да качва.
|