Witam, mam mały problem z uploadem obrazków, bazowałem na gotowym rozwiązaniu, jednak coś nie działa i ciągle mam błąd :/
o to kod
<?
if(isset($_POST['submit'])) { //see if submit button is pressed.
//check if they decided to upload a pic:
if($_FILES['userfile']['size'] > 1) {
$max_size = 10000000000;
$max_height = 300;
$max_width = 300;
}
//check file-size (in bytes):
if(($_FILES['userfile']['size'] > $_POST['MAX_FILE_SIZE']) || ($_FILES['userfile']['size'] > $max_size)) {
die("<BR><BR>Błąd, rozmiar pliku jest zbyt duży!: (<b>" . $_FILES['userfile']['size'] . "</b>)."); }
//check the extension.
$array = explode(".", $_FILES['userfile']['name']); $ext = $array[$nr-1];
if(($ext !="jpg") && ($ext !="jpeg") && ($ext !="png"))
die("<BR><BR>Dozowolone są tylko rozszerzenia jpg i png");
//CHECK TYPE: (what the browser sent)
if(($_FILES['userfile']['type'] != "image/jpeg") && ($_FILES['userfile']['type'] != "image/pjpeg") && ($_FILES['userfile']['type'] != "image/png")) {
die("<BR><BR>Dozowolone są tylko rozszerzenia jpg i png"); }
//DOUBLE CHECK TYPE: if image MIME type from GD getimagesize() -In case it was a FAKE!
if(($info['mime'] != "image/jpeg") && ($info['mime'] != "image/pjpeg") && ($info['mime'] != "image/png")) {
die("<BR><BR>Dozowolone są tylko rozszerzenia jpg i png"); }
//check file size (length & width)
if(($info[0] > $max_width) || ($info[1] >$max_height)) {
die("<BR><BR>Obrazek jest za duży(<b>" . $info[0] . "</b> x <b>" . $info[1] . "</b>). Maksymalny rozmiar obrazka ". $max_height . " x ". $max_width ."."); }
//rename file, move it to location.
//get max number of images the user has uploaded
$m = mysql_query("SELECT max(user_images) as `total_images` FROM `images` WHERE `user_id` = '".$_SESSION['user_id']."'"); if(!$m) die('An Error Occurred.'); if($result->total_images <= 0) {
$image_number = 1;
} else {
$image_number = $result->total_images + 1;
} //end if
$filename = strtolower($_SESSION['username']) . $image_number;
if(move_uploaded_file($_FILES['userfile']['tmp_name'] , $_SERVER['DOCUMENT_ROOT']."/img/".$filename . '.' . $ext)) { echo("File uploaded successfully."); } else {
echo("An error occurred while uploading."); }//end upload
} //end is_uploaded_file
} else { //display form ?>
<form enctype="multipart/form-data" action="<? $_SERVER['PHP_SELF']; ?>" method="post" name="uploadImage" />
<input type="hidden" MAX_UPLOAD_SIZE = "10000000000" />
<input type="file" name="userfile" size="35" />
<input type="submit" name="submit" value="Upload Image">
<? } //end else ?>
za kazdym razem pokazuje mi się informacja o zbyt duzym rozmiarze pliku, czy ktoś może mi pomoc i powiedziec gdzie jest blad?(IMG:
http://forum.php.pl/style_emoticons/default/smile.gif)