Freaky Posted March 15, 2008 Report Posted March 15, 2008 (edited) 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 March 15, 2008 by Freaky
Zandis Murāns Posted March 15, 2008 Report Posted March 15, 2008 (edited) 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 March 15, 2008 by Zandis Murāns
Freaky Posted March 15, 2008 Author Report Posted March 15, 2008 (edited) ā 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 March 15, 2008 by Freaky
Freaky Posted March 15, 2008 Author Report Posted March 15, 2008 nu, lai pirms bildes parādīšanas(ja bilde pārsniedz 250x300) bilde tiek samazināta līdz width ir 300, bet height paliek proporcionāls?
andrisp Posted March 16, 2008 Report Posted March 16, 2008 http://lv.php.net/manual/en/function.imagecopyresized.php komentāros ir piemēri kā rēķināt proporcionālus izmērus.
Recommended Posts