Jump to content
php.lv forumi

Parādīt bildi


Freaky

Recommended Posts

Nu krč users ielādē bildi

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Bilde:</label>
<input type="file" name="file" id="file" /><br>
<input type="submit" name="submit" value="Sūtīt" /><br>
<b>(tikai .jpg vai .gif; max 450kb)</b>
<br />
</form>

Bilde tiek apstrādāta

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 450000))
 {
 if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
 if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " - <b>tāda bilde jau datubāzē ir.</b>";
}
 else
{
echo "<b>Paldies!</b><br><br>";
echo "Ielādēts: " . $_FILES["file"]["name"] . "<br />";
echo "Tips: " . $_FILES["file"]["type"] . "<br />";
echo "Lielums: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))
  {
  echo $_FILES["file"]["name"] . " - <b>tāds fails jau datubāzē ir.</b> ";
  }
else
  {
  move_uploaded_file($_FILES["file"]["tmp_name"],
  "upload/" . $_FILES["file"]["name"]);
  }
}
 }
else
 {
 echo "<b>Sačakarēts fails. (MAX 450Kb un tikai jpg, gif formātos)</b>";
 }
?>

Un vajadzētu, lai bilde vēl pēc tam apakšā parādās (Ja viss ir OK).

Ja ir kādās kļūdas lūdzu palīdziet izlabot. :)

Edited by Freaky
Link to comment
Share on other sites

Krč yo, možet šitā:

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 450000))
 {
 if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
 if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " - <b>tāda bilde jau datubāzē ir.</b>";
}
 else
{
echo "<b>Paldies!</b><br><br>";
echo "Ielādēts: " . $_FILES["file"]["name"] . "<br />";
echo "Tips: " . $_FILES["file"]["type"] . "<br />";
echo "Lielums: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))
  {
  echo $_FILES["file"]["name"] . " - <b>tāds fails jau datubāzē ir.</b> ";
  }
else
  {
  move_uploaded_file($_FILES["file"]["tmp_name"],
  "upload/" . $_FILES["file"]["name"]);
echo '<img src="'."upload/" . $_FILES["file"]["name"].'"/>';
  }
}
 }
else
 {
 echo "<b>Sačakarēts fails. (MAX 450Kb un tikai jpg, gif formātos)</b>";
 }
?>

Edited by Zandis Murāns
Link to comment
Share on other sites

ā un vēl kā varētu pielikt tādu bildes pārbaudi kā, ja bilde ir piemēram vairāk kā 400x400 viņa tiek parādīta samazināta par 50% nevis līdz noteiktam augstumam un platumam?

Edited by Freaky
Link to comment
Share on other sites

×
×
  • Create New...