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ă" />

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

Upload.php file

//$ext=pathinfo($fis, PATHINFO_EXTENSION);
if ($eror > 0)
echo "Eroare: " . $eror . "<br />";
if (file_exists($cale . $fis))
{ // verificare dacă fişierul există deja pe server
echo "Fisierul există deja.";
{ // 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