Simple form for uploading files

One of the easiest ways to upload a file via a PHP interface would be to use two files:

  • file containing the form of charge and can be HTML or if you need something dynamic, PHP
  • the upload file (upload.php), which is invoked into the body of the FORM tag.

Initial file

<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="fisier" />
<input type="submit" name="incarc" value="Încarcă" />
<input type="reset" name="anul" value="Anulează" />
</form>

It is noticed that the variable $ext is commented, being suggested, only if the manipulation of the extension is desired.

Upload.php file


<?php
$fis=$_FILES["fisier"]["name"];
//$ext=pathinfo($fis, PATHINFO_EXTENSION);
$eror=$_FILES["fisier"]["error"];
$cale="../a/";
$dir_tmp=$_FILES["fisier"]["tmp_name"];
if ($eror > 0)
{
echo "Eroare: " . $eror . "<br />";
}
else
{
if (file_exists($cale . $fis))
{ // verificare dacă fişierul există deja pe server
echo "Fisierul există deja.";
}
else
{ // mutare fişier din folderul temporar al serverului în cel final
move_uploaded_file($dir_tmp, $cale . $fis);
echo "Fişier încărcat cu succes!";
}
}
?>

Author: Ovidiu.S

I am quite passionate about this professional area as if I know something - no matter how little - I want to share it with others.

Leave a Reply

Your email address will not be published. Required fields are marked *