Website Development Prices

Search Blog

Wednesday, June 29, 2016

Prebacivanje fajlova (Uploading files)

Da biste prebacivali fajlove koristicete formu tipa multipart, koju cete napraviti uz pomoc atributa enctype elementa <form>

Primer: 

<form enctype="multipart/form-data" action="prebacivanje-fajlova.php" method="post">
.
.
.
.

</form>

Prebacivanje cete obaviti pomocu kontrole file, koja se praviti uz pomoc elementa <input type="file">Kontroli cemo dati ime "poruka", pomocu kojeg cemo kasnije (u sledecem clanku) da pristupimo prebacenom fajlu.   


Nastavak primera:

<!DOCTYPE html>
<html>
<head>
<title>HTML forme</title>
</head>

<body>
<h1>Prebacivanje fajlova</h1>

<h3>Prebacivanje fajla poruka.txt</h3>

<form enctype="multipart/form-data" 
                    action="prebacivanje-fajlova.php" method="post">
Prebacivanje fajla: <input name"poruka" type="file">

<br /><br />
<input type="submit" value="Prebacite fajl">
</form>

</body>
</html>

Kreiranje dokumenta poruka - desni klik na Desktop, selektujte Newiz padajuceg menija izaberite Text Document. Novom tekst dokumentu dajte ime, npr. poruka i Enter. U ovaj dokument ubacite neki tekst. Ovaj fajl mozete prebaciti u folder prebacivanje-fajlova. Putanja u mom primeru je: C:/xampp2/htdocs/PHPtuts/prebacivanje-fajlova.




Rezultat:






U sledecem clanku, za pristup prebacenom fajlu koristicemo superglobalni niz $_FILES.  funkciju fopen.

To transfer files you would use form type of multipart, which you will create with the help of enctype attribute of the element <form>.

Example:

<form enctype="multipart/form-data" action="uploading-files.php" method="post">
.
.
.
.

</form>

Uploading will be done using the control file, which is made with the help of the <input type="file">. We will give the name "message" to this control,  which we will later use (in the next article) to access the transferred file.

Example continued:

<!DOCTYPE html>
<html>
<head>
<title>HTML forms</title>
</head>

<body>
<h1>Uploading files</h1>

<h3>Uploading file message.txt</h3>

<form enctype="multipart/form-data" 
 action="uploading-files.php" method="post">
Uploading file: <input name"message" type="file">

<br /><br />
<input type="submit" value="Upload file">
</form>

</body>

</html>

Creating a document message - right click on the Desktop, select New, from the drop-down menu, choose Text Document. Name new text document, for example, message and press Enter. Place some text in this file. This file you can move to the uploading-files folder. The path in my example is: C:/xampp2/htdocs/PHPtuts/uploading-files.




Result:










In the next article, to access the transferred file we will use superglobal array $_FILES.  function fopen.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.