Jump to content
php.lv forumi

php konfiguraacija


Recommended Posts

Cik nopratu tu gribi kautkaadu file upload uztaisiit, nafig tev noraadiit upload diru?

Man kautkad sev bija jaauzcepina scripts - moška tev noder:

<?
if (($_SERVER['PHP_AUTH_USER']!="Chickenz")||($_SERVER['PHP_AUTH_PW']!="kaka")) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo "<font color=\"red\" face=\"verdana\" size=\"2\">Sorry vecais, tu neesi admins!!!</font>";die;}
else{
?>
<html>

<head>
<meta http-equiv="Content-Language" content="lv">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1257">
<LINK href="style.css" type="text/css" rel="stylesheet">
<title>Failu upload!</title>
</head>

<body>

<table border="0" cellpadding="0" cellspacing="5" style="border-collapse: collapse" width="500" class="main_tab">
 <tr><FORM ENCTYPE="multipart/form-data" ACTION="imageupload.php" METHOD="POST">
   <td align="center" width="450" colspan="2"><?echo "<b>Sveiks {$_SERVER['PHP_AUTH_USER']}!!!</b>";?></td>
 </tr>
 <tr>
   <td align="center" width="100"> </td>
   <td align="center" width="400"> </td>
 </tr>
 <tr>
   <td align="center" width="100">Fails:</td>
   <td align="center" width="400"><INPUT TYPE="file" NAME="userfile" class="upload" size="20"> <INPUT TYPE="submit" VALUE="OK" class="b1"></td>
 </tr>
 <tr>
   <td align="center" width="450" colspan="2"> </td>
 </tr>
 <tr>
   <td align="center" width="450" colspan="2">
<?php
extract($_POST, EXTR_SKIP);
$dir = "file/";
$msize = 1024000;

if (!isset($HTTP_POST_FILES['userfile'])) exit;
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
if ($HTTP_POST_FILES['userfile']['size']>$msize){
echo "Fails ir pārāk liels<br>"; exit; }
if (($HTTP_POST_FILES['userfile']['type']=="image/gif")||
($HTTP_POST_FILES['userfile']['type']=="image/pjpeg")||
($HTTP_POST_FILES['userfile']['type']=="image/jpeg")||
($HTTP_POST_FILES['userfile']['type']=="image/bmp")||
($HTTP_POST_FILES['userfile']['type']=="image/png")) {

if (file_exists($dir . $HTTP_POST_FILES['userfile']['name'])){
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $dir .
$HTTP_POST_FILES['userfile']['name']);
echo "<b>$realname</b> Šāds fails jau existē!!!";exit;}
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $dir .
$HTTP_POST_FILES['userfile']['name']);
if (!$res){
echo "<b>$realname</b>Failu nav iespējams aploudot!!! :(<br>";exit;}
else{echo "<b>Fails veiksmīgi aploudoc!!!</b><br><br>"; }

echo "Faila nosaukums: <b>".$HTTP_POST_FILES['userfile']['name']."</b><br>";
echo "Faila izmērs: <b>".round($HTTP_POST_FILES['userfile']['size']/1024) ." KB</b><br>";
echo "Faila tips:<b> ".$HTTP_POST_FILES['userfile']['type']."</b><br>";
} else { echo "Neatļauts faila tips<br>"; exit; }}
?>
   </td>
 </tr>
 <tr>
   <td align="center" width="450" colspan="2"><?
echo "<br><b>Direktorijā $dir ir šādi faili:<br><br></b>";
$handle = opendir($dir); 
while (false !== ($file = readdir($handle))) { 
   if ($file != "." && $file != "..") { 
       echo "$file<br>"; 
   } 
}
closedir($handle); ?>
   </td>
 </tr>
 </table>
</FORM>
</body>

</html>
<?}?>

Link to comment
Share on other sites

2 Chickenz: Cik sapratu, tad viņam ir problēma ar to, ka neder norādītā temp direktorija uploadam (tā direktorija, kurā webserveris saglabā uploadotos failus, pirms php tos sāk apstrādāt). Tavā gadījumā $HTTP_POST_FILES['userfile']['tmp_name']...

Link to comment
Share on other sites

upload_temp_dir ir viens no tiem uzstādījumiem, ko var mainīt tikai ar php.ini vai arī ar httpd.conf failiem.. tā kā ja pareizi sapratu jautājumu, tad diez vai izdosies vajadzīgais efekts.

 

vēl var strīdēties par to, vai tas tiešām tev ir vajadzīgs ;)

Link to comment
Share on other sites

×
×
  • Create New...