Не сте регистриран! Регистрирайте се БЕЗПЛАТНО, за да използвате услугите на сайта!

 Прост Upload скрипт
Автор  porostorm (07.02.2006 18:39) съобщение до автора
Погледнат  1363 пъти добави към любими
Оценка добави коментар
Гласове  4 изпрати на приятел
Коментари  (1) абонирай се за PHP
     
porostorm
     
 

Трябва да създадете папка за качените файлове, в случая "files" и текстов документ: "log.txt. CODE
1
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
@session_start();
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this"http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

// Къде да се записват качените файлове?

$upload_dir = "files/";
$upload_url = $url_dir."/files/";
$message ="log.txt";

/************************************************************
  •     Create Upload Directory
************************************************************/
if (!is_dir("files")) {
 
if (!mkdir($upload_dir))
    
die ("upload_files directory doesn't exist and creation failed");
 
if (!chmod($upload_dir,0755))
    
die ("change permission to 755 failed.");
}

/************************************************************
  •     Process User's Request
************************************************************/
 
if ($_REQUEST[del])  {   
print "<script>window.location.href='$url_this?message=deleted successfully'</script>";
}
else if ($_FILES['userfile']) {
 
$message = do_upload($upload_dir, $upload_url);
 
print "<script>window.location.href='$url_this?message=$message'</script>";
}
else if (!$_FILES['userfile']);
else
  
$message = "Invalid File Specified.";

/************************************************************
  •     List Files
************************************************************/
$handle=opendir($upload_dir);
$filelist = "";
while ($file = readdir($handle)) {
  
if(!is_dir($file) && !is_link($file)) {
     
$filelist .= "<br><a href='$upload_dir$file'>".$file."</a>";

  
}
}

function do_upload($upload_dir, $upload_url) {

  
$temp_name = $_FILES['userfile']['tmp_name'];
  
$file_name = $_FILES['userfile']['name'];
  
$file_type = $_FILES['userfile']['type'];
  
$file_size = $_FILES['userfile']['size'];
  
$result    = $_FILES['userfile']['error'];
  
$file_url  = $upload_url.$file_name;
  
$file_path = $upload_dir.$file_name;

 
//File Name Check
   
if ( $file_name =="") {
      
$message = "Invalid File Name Specified";
      
return $message;
   
}
  
//File Size Check
   
else if ( $file_size > 999999999999999999999) {
      
print $file_size;
       
$message = "Размера на файла е много голям.";
       
return $message;
   
}
  
//File Type Check
   
else if ( $file_type == "text/plain"
         ||
$file_type == "application/force-download"
         ||
$file_type == "application/octet-stream") {
       
$message = "Sorry, You cannot upload any script file" ;
       
return $message;
   
}

   
$result  =  move_uploaded_file($temp_name, $file_path);
   
if (!chmod($file_path,0755))
       
$message = "change permission to 755 failed.";
   
else
     
$message = ($result)?"$file_name($file_type) uploaded successfully." :
               
"Somthing is wrong with uploading a file.";

   
return $message;
}

?>
<
table  style="width: 40%" align="center" valign="top">
  <
tr>
    <
td>
<
div align="center" style="font-size: 19px; font-weight: bold">
</
table>
<
body bgcolor="#667987"><center>
   <
font color=red><?=$_REQUEST[message]?></font>
   <
form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
     Качи фаил: <
input type="file" id="userfile" name="userfile" size="20">
     <
input type="submit" name="upload" value="Upload">
   </
form>
   
   <
b>До сега потребителите ни са качили следните файлове:</b>
   <
hr style="color:yellow; background-color:black; height:1px;
  margin-right:0; text-align:right; border:0px
">
   <?=
$filelist?>
</
center>

<?
if ($_REQUEST[debug]==1) print "------------------Debugging Info----------------<br>";
if ($_REQUEST[debug]==1) print "site=$site_name<br>dir=$url_dir<br>url=$url_this<br>";
if ($_REQUEST[debug]==1) print "upload dir=$upload_dir<br>upload url=$upload_url<br>";
?>



Ключови думи: PHP upload файл ъплоуд




 За автора: porostorm  
Нямам какво да пиша за мене :)
   
 1 посетител чете този скрипт (0 потребители и 1 гост)  
Активни потребители: ---
   
  

Еmail  
 

Погледнах този скрипт ,но определено не ми хареса и има много недостатъци...
 

  masterfree на 01.08.2007 14:45

 

 
  • Интересно от Софтуер
 
  • Интересно от myLINKS
 
 
 
 



IT-PLACE.NET © 2004 - 2008