student Posted December 17, 2010 Report Share Posted December 17, 2010 Jau 3ais topiks šovakar,bet gan jau serveri nepārkarsīs:)) Es nokopēju visus datus no adreses- http://www.w3schools.com/PHP/php_file_upload.asp kur ir parādīts kā ievietot iekšā mapē upload bildes utt.Man viss aiziet un darbojas,bet apstājos pie kaut kādas bezjēdzības. Varu ievietot tikai dažas jpg bildes un gandrīz visām rādās invalid file.Pieļaujamo izmēru esmu mainījis. Kāds var to papētīt un pateikt kādēļ iet tikai retās jpg bildes. <html> <body> <form action="upload_file.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="Submit" /> </form> </body> </html> <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> Quote Link to comment Share on other sites More sharing options...
briedis Posted December 17, 2010 Report Share Posted December 17, 2010 Izmanto code tagu, tak tas kods nav pārskatāms! Normālas atkāpes arī ir vajadzīgas! Quote Link to comment Share on other sites More sharing options...
Blitz Posted December 18, 2010 Report Share Posted December 18, 2010 (edited) Mācies atkļūdot pats savu kodu. 1. Ja tu redzi ka rāda invalid file, tas nozīmē ka sis IFs neizpildās if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) 2. Tātad tu redzi ka vainu kļūda faila izmērā vai mime tipā. 3. Nutad paskaties kādus tiešu datus tev rāda print_r($_FILES["file"]) 4. Un ja netiec galā tad griezies jau te ar konkrētu problēmu, un saki ka jpeg bildei type uzrādā image/poo nevis image/jpeg, ko dariit? Edited December 18, 2010 by Blitz Quote Link to comment Share on other sites More sharing options...
student Posted December 18, 2010 Author Report Share Posted December 18, 2010 Ok.Tagad uzdošu konkrētāk. Ja es atrodu reto bildi,kuru var aizsūtīt uz upload tad man izvadās šāds print_r($_FILES["file"]): Array ( [name] => 002.JPG [type] => image/jpeg [tmp_name] => C:\wamp\tmp\php18D.tmp [error] => 0 => 1645268 ) Bet ja man ir kārtējā bilde ar savu invalid file tad man izvadās šāds print_r($_FILES["file"]): Array ( [name] => 016.JPG [type] => [tmp_name] => [error] => 1 => 0 ) Tagad varētu palīdzēt ar kļudas meklēšanu? Quote Link to comment Share on other sites More sharing options...
Blitz Posted December 18, 2010 Report Share Posted December 18, 2010 (edited) Tu redzi ka error ir 1. Tad tu ieej šeit http://php.net/manual/en/features.file-upload.errors.php un redzi ka tur stāv rakstīts ka Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini. kas savukārt nozīmē ka PHP neatlauj tik lielu failu augšuplādēt. To vari regulēt gan php.ini "upload_max_filesize = 10M", gan skripta sākumā ieliekot ini_set("upload_max_filesize","10M"); Parbaudīt kāda vērtība šobrīd ir aktīva vari ar echo ini_get("upload_max_filesize"); Labojot php.ini jaatceras ka webserveris ir jāpārstartē. Edited December 18, 2010 by Blitz Quote Link to comment Share on other sites More sharing options...
student Posted December 18, 2010 Author Report Share Posted December 18, 2010 Skaidrs.Tad varētu man palīdzēt izveidot līdz galam to kodu,jo kad es arī ielieku tieši pēc <?php ini_set("upload_max_filesize","10M"); ... Un izdzēšu to rindu ar ($_FILES["file"]["size"] < 1000000000000000000) Un vēl pielieku echo ini_get("upload_max_filesize"); Tad man izvadās šādi Invalid file Array ( [name] => 016.JPG [type] => [tmp_name] => [error] => 1 => 0 ) 2M Tad ko tur vēl darīt? Quote Link to comment Share on other sites More sharing options...
Blitz Posted December 18, 2010 Report Share Posted December 18, 2010 echo ini_get("upload_max_filesize"); neko neizdrukā? Apskaties cik ir post_max_size iekš php.ini ... Quote Link to comment Share on other sites More sharing options...
student Posted December 18, 2010 Author Report Share Posted December 18, 2010 Jap,es nomainīju tajā php.ini maksimālo faila izmēru no 2 uz 20 un tagad viss iet!Liels paldies par palīdzību! Quote Link to comment Share on other sites More sharing options...
daGrevis Posted December 18, 2010 Report Share Posted December 18, 2010 Nu re! Debug'am ir spēks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.