Engjujt Shqipetare Forum/portal
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Shko poshtë
IC4E
IC4E
Anetari ri
Anetari ri
 <b>Gjinia</b> Gjinia : Male
<b>Shteti</b> Shteti : Shqipëria
<b>Postime</b> Postime : 4
 <b>Vendndodhja</b> Vendndodhja : Kosove
<b>Anetaresuar</b> Anetaresuar : 15/05/2012

Uploading file – PHP Empty Uploading file – PHP

Wed 1 Apr 2015 - 14:52
ne ket pjes te do te pedorent funksionet bazike qe nuk do te ken ndonje veshtiresi. Qellimi i keti tutorial eshte qe te mesoheni se si mund te behet uploadimi i nje file duke perdorur PHP dhe HTML format.
Kerkohet:

  • HTML & PHP Bazike

  • PHP-Host

  • Mundesin e uploadimit (Permission)


Hapi 1
Krijoni nje html file dhe shtoni kodin

Code:

Kodi:
<html>
<body>
[size=12][/size]
[size=12]<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Upload" />
</form>[/size]

Kodi:
</body>
</html>

Attributi enctype [t]multipart/form-data[/t]  na jep mundesi qe te perdorim qfardo fajlli qe ne na nevojitet.
Ne inputin e par atributi [t]file[/t]: na lejon neve qe te kemi mundesin e uploadimit te file. duke pedorur ket pjes ne browser do te afishohet mundesia per selektimin e file qe deshiron te uploadoj

[t]action[/t]  attribuit qe eshte e shkruar [t]action=”upload.php”[/t] tregon se processimi do te behet tek file upload.php pasi te dergohen te dhenat(pas klikimit te buttonit per processim ‘submit’) qe ne ket rast pasi te klikohet butoni me tekstin Upload do te filloj processimi e asaj te dhane.
Hapi 2
Ne ket pjes do te shkruhet kodi i cili e ben processimin e file te uploaduar.
Krijoni nje file me emrin upload.php emri qe i lini file duhet te perputhet me emrin e action=”upload.php”
Shtoni kodin ne vazhdim

Code:

Kodi:
<?php
// per kontrollimin e erroreve.
if ($_FILES["file"]["error"] > 0)
{
print("Error: ". $_FILES["file"]["error"]);
}
[size=12][/size]
[size=12]else
{
//Per afishimin e statistikave.
print("Uploaded: " . $_FILES["file"]["name"]. "<br />");
print("Type: " . $_FILES["file"]["type"] . "<br />");
print("Size: " . $_FILES["file"]["type"] . "<br />");[/size]

Kodi:
// Ruaj file.
move_uploaded_file($_FILES["file"]["tmp_name"],
"uploads/" . $_FILES["file"]["name"]);
}
?>

[t]move_upload_file(…)[/t] kerkohet te behet  se file i cili ngarkohet nga klienti ne server ajo se pari ngarkohet ne nje lokacion te quajtur temporary ne momentin qe ngarkohet ekzekutimi i keti funksioni perfundon. duke e perdor move_uploaded_file(..) ne e vendosim at file ne nje lokacion permanent Relative ose absolute qe ne rastin ton eshte relative qe nenkupton.
~/ do te ngarkohet file ne at lokacion ku gjende file upload.php

Hapi 3
Ne mundemi te bejm disa ndryshime tek uploadimi i file si p.sh madhesin,tipin,emrin,

Code:

Kodi:
_$FILES["file"]["type"]
_$FILES["file"]["size"]

Ketu e keni nje pjes te vogel te demonstruar me tipin gif
Code:

Kodi:
if (_$FILES["file"]["type"] == "image/gif")
print("Ky file eshte gif.");

 
Code:

Kodi:
if (_$FILES["file"]["size"] < 1000000)
print("File size: " . $_FILES["file"]["size"] . ". <br />");
[size=12][/size]

Kodi:
else
print("Madhesia eshte shum e madhe. <br />");






http://seec0m.altervista.org/uploading-file-php
Mbrapsht në krye
Drejtat e ktij Forumit:
Ju nuk mund ti përgjigjeni temave të këtij forumi