09 - Ngarkimi dhe Shkarkimi i skedareve


Ne kete leksion


Ngarkimi i skedareve ne server

lifeupload.php

<html>
<head>
<title>File upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="upload.php" enctype="multipart/form-data"
 method="post" name="form1">
 
 <input name="f1" type="file" size="50"><br>
 <input name="f2" type="file" size="50"><br>

 
 <input type="submit" value="ngargo" name="submit">
 
 </form>


</body>
</html>


Nese duam ta limitojme perdoruesin ne llojin e file-it qe do te ngarkoje mjafton te shtojme
tek forma atributin : accept="image/*" ose me teper te shtohet : 
accept='image/*|audio/*|video/*'.
Nese duam nje format konkret shtojme:
accept="application/pdf"


updload.php

<?php
echo '<p>';
  echo "Upload: " . $_FILES["f1"]["name"] . "<br>";
  echo "Type: " . $_FILES["f1"]["type"] . "<br>";
  echo "Size: " . ($_FILES["f1"]["size"] / 1024) . " kB<br>";
  echo "Stored in: " . $_FILES["f1"]["tmp_name"];
echo '</p>';
echo '<p>';
  echo "Upload: " . $_FILES["f2"]["name"] . "<br>";
  echo "Type: " . $_FILES["f2"]["type"] . "<br>";
  echo "Size: " . ($_FILES["f2"]["size"] / 1024) . " kB<br>";
  echo "Stored in: " . $_FILES["f2"]["tmp_name"];
echo '</p>';

$emri1="images/".$_FILES["f1"]["name"];
$emri2="images/".$_FILES["f2"]["name"];
move_uploaded_file($_FILES["f1"]["tmp_name"],$emri1);
move_uploaded_file($_FILES["f2"]["tmp_name"],$emri2);

echo "<p>skedaret u ngarkuan</p>";
echo "<p><a href='".$emri1."'>
<img src='".$emri1."' width='400'></a></p>";
echo "<p><a href='".$emri2."'>
<img src='".$emri2."' width='400'></a></p>";
?>



Shkarkimi i skedareve ne menyre te kontrolluar



<?php 
$file=fopen('d:\\audio.mp3','r') or exit('nuk e hap dot skedarin');
header('Content-Type:audio/mp3');
header("Content-Disposition: attachment; filename=mp.mp3;" );
while(!feof($file))
{
$char=fgetc($file);
echo $char;
}

fclose($file);
?>
Ć
beyonce.mp3
(3518k)
Leogena Zhaka,
Feb 26, 2015, 6:21 AM