2016-04-06 26 views
-1

Sitemde, sayfanın normal kullanıcıların indirebileceği sözcük dosyalarını yükleyebileceği bir sayfa ekledim. Kodumu ilk kez denedim, ancak iyi indirildi ama şimdi tekrar yüklediğim bir dosyayı, bir zip dosyası olarak indirdiğimde ve yüklenen belgeyi içermediğinde. Neler ters gitti?Dosyalar - Karşıdan Yükle, İndirin ve Sil PHP

upload_file.php

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>Uploading File</title> 
<link rel="stylesheet" href="style.css" type="text/css" /> 
</head> 
<body> 
<div id="header"> 
<label>Upload File</label> 
</div> 
<div id="body"> 
<form action="upload.php" method="post" enctype="multipart/form-data"> 
<input type="File" name="File" /> 
<button type="submit" name="btn-upload">Upload</button> 
</form> 
    <br /><br /> 
    <?php 
if(isset($_GET['success'])) 
{ 
    ?> 
     <label>File Uploaded Successfully... <a href="view.php">click here to view file.</a></label> 
     <?php 
} 
else if(isset($_GET['fail'])) 
{ 
    ?> 
     <label>Problem While File Uploading !</label> 
     <?php 
} 
else 
{ 
    ?> 
     <?php 
} 
?> 
</div> 
</body> 
</html> 

upload.php

<?php 
include_once("functions.php"); 
if(isset($_POST['btn-upload'])) 
{  

$file = rand(1000,100000)."-".$_FILES['File']['Name']; 
    $file_loc = $_FILES['File']['tmp_name']; 
$file_size = $_FILES['File']['Size']; 
$file_type = $_FILES['File']['Type']; 

// new file size in KB 
$new_size = $file_size/1024; 
// new file size in KB 

// make file name in lower case 
$new_file_name = strtolower($file); 
// make file name in lower case 

$final_file=str_replace(' ','-',$new_file_name); 

if(move_uploaded_file($file_loc,$final_file)) 
{ 
    $sql="INSERT INTO Uploads(File,Type,Size) VALUES('$final_file','$file_type','$new_size')"; 
    mysql_query($sql); 
    ?> 
    <script> 
    alert('successfully uploaded'); 
     window.location.href='view.php?success'; 
     </script> 
    <?php 
} 
else 
{ 
    ?> 
    <script> 
    alert('error while uploading File'); 
     window.location.href='upload_file.php?fail'; 
     </script> 
    <?php 
} 
} 
?> 

view.php

<?php 
include_once("functions.php"); 

?> 

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>File Uploading With PHP and MySql</title> 
<link rel="stylesheet" href="style.css" type="text/css" /> 

</head> 
<body> 
<div id="header"> 
<label>View Files</label> 
</div> 
<div id="body"> 
<table width="80%" border="1"> 
    <tr> 
    <th colspan="4">Uploads...</th> 
    </tr> 
    <tr> 
    <td>File Name</td> 
    <td>File Type</td> 
    <td>File Size(KB)</td> 
    <td>Download</td> 
    </tr> 
    <?php 
$sql="SELECT * FROM Uploads"; 
$result_set=mysql_query($sql); 
while($row=mysql_fetch_array($result_set)) 
{ 
    ?> 
     <tr> 
     <td><?php echo $row['File'] ?></td> 
     <td><?php echo $row['Type'] ?></td> 
     <td><?php echo $row['Size'] ?></td> 
     <td><a href="<?php echo $row['File'] ?>" target=" ">Download File</a></td> 
     </tr> 
     <?php 
} 
?> 
    </table> 

</div> 
</body> 
</html> 

2) Ayrıca, yönetici kullanıcının gerekmedikçe dosyaları silebilmesini de istiyorum. Bunu nasıl yaparım?

cevap

İlgili konular