drellout Posted December 28, 2009 Report Share Posted December 28, 2009 (edited) Laba nakts, php.lv lietotāji es hot skriptā atradu upload sistēmu, bet sastapos ar vienu problēmu, bet tā itkā viss strādā <?php $allowed = array("jpeg","gif","png","bmp", "jpg", "rar", "exe", "jpg", "hltv", "dem", "txt", "zip"); ?> <form action="" method="post" enctype="multipart/form-data"> Choose file to upload <input name="upload" type="file"> <input name="sb" id="sb" value="Upload" type="submit"> </form> <?php if(isset($_POST['sb'])) { //check for valid extension $pathInfo = pathinfo($_FILES["upload"]["name"]); $extension = $pathInfo['extension']; //choose directory/foolder to place the file in $dir = "files"; if(!in_array($extension, $allowed)) die("Extension not allowed!"); if(move_uploaded_file($_FILES['upload']['tmp_name'], "$dir/".$_FILES['upload']['name'])) { print "Your new file can be viewed/download at <input name=\"newfile\" value=\"http://$_SERVER[HTTP_HOST]/inc/upload/$dir/".$_FILES['upload']['name']."\" type=\"text\" style=\"width: 300px\">"; }else{ print "File could not be uploaded"; } $DatabaseHost = "localhost"; $DatabaseUsername = "root"; $DatabasePassword = "pw"; $DatabaseName = "file"; $connection = mysql_connect($DatabaseHost, $DatabaseUsername, $DatabasePassword) or die("Cannot connect to MySQL!"); mysql_select_db($DatabaseName, $connection) or die("Cannot find database!"); $sql = "insert into files values (null, '".htmlentities($_FILES['upload']['name'])."', 'now()', '$_SERVER[REMOTE_ADDR]')"; $rs = mysql_query($sql); print mysql_error(); } ?> <br/> Kad tajā skriptā ej piemēram http://ip/inc/upload/index.php tad viss ok viss iet, bet kad sataisa lai viņš gruzītos/inkludotos webā tad met ārā erorus Warning: move_uploaded_file(files/FL052.zip) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\AppServ\www\inc\upload\upload.php on line 16 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\TEMP\phpFB.tmp' to 'files/FL052.zip' in C:\AppServ\www\inc\upload\upload.php on line 16 File could not be uploaded Edited December 28, 2009 by drellout Quote Link to comment Share on other sites More sharing options...
2easy Posted December 28, 2009 Report Share Posted December 28, 2009 http://www.php.net/manual/en/features.safe-mode.functions.php Quote Link to comment Share on other sites More sharing options...
drellout Posted December 28, 2009 Author Report Share Posted December 28, 2009 Atvaino, bet es nesapratu, vai lūdzu vari palīdzēt tā lai es apmēram saprastu kas ir jāedito ? Quote Link to comment Share on other sites More sharing options...
2easy Posted December 28, 2009 Report Share Posted December 28, 2009 move_uploaded_file() vietā pamēģini rename() Quote Link to comment Share on other sites More sharing options...
drellout Posted December 28, 2009 Author Report Share Posted December 28, 2009 move_uploaded_file() vietā pamēģini rename() ir rename, tgd met āra šitādu eroru Warning: rename(C:\WINDOWS\TEMP\php11D.tmp,files/FL056.zip) [function.rename]: No such file or directory in C:\AppServ\www\inc\upload\upload.php on line 16 File could not be uploaded Quote Link to comment Share on other sites More sharing options...
2easy Posted December 28, 2009 Report Share Posted December 28, 2009 značit fails vnk nav uploadots. pirms move, vajag pārbaudīt $_FILES['upload']['error'] more info here http://php.net/manual/en/features.file-upload.php Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted December 28, 2009 Report Share Posted December 28, 2009 Skriptam nepatīk, ka tu nenorādi pilno ceļu (iespējams, ka windows arī nepatīk slash /)... Pamēģini tam $files mainīgajam piešķirt pilno ceļu uz mapi. Attiecībā par rename() lietošanu move_uploaded_file() vietā, man šķiet, ka tas nav pareizi. [edit] Pareizāk sakot droši vien tajā vietā, kurā atrodas skripts, kurā tiek includēts šis uploadošanas pasākums, nav tāda direktorija "files" Quote Link to comment Share on other sites More sharing options...
2easy Posted December 28, 2009 Report Share Posted December 28, 2009 Attiecībā par rename() lietošanu move_uploaded_file() vietā, man šķiet, ka tas nav pareizi. pilnīgi piekrītu. vnk es sākumā padomāju, ka viņam tur safe mode ir (jo cik sapratu, it kā uz viena servera strādājot, bet kkur citur nē), un tā kā safe modē laikam move_uploaded_file() ir atslēgts, tad ieteicu rename() (lai vispār kkas strādātu). bet tgd jau skaidrs, ka šis ir labs piemērs, ka internetā var atrast daudz skriptus, kuru kvalitāte ir zem katras kritikas. šeit nav elementāra error apstrāde (varbūt bija pārāk liels fails, vai vispār nav nosūtīts fails, varbūt nepareizs name?) sazin kas tur ir... Quote Link to comment Share on other sites More sharing options...
drellout Posted December 28, 2009 Author Report Share Posted December 28, 2009 Skriptam nepatīk, ka tu nenorādi pilno ceļu (iespējams, ka windows arī nepatīk slash /)... Pamēģini tam $files mainīgajam piešķirt pilno ceļu uz mapi. Attiecībā par rename() lietošanu move_uploaded_file() vietā, man šķiet, ka tas nav pareizi. [edit] Pareizāk sakot droši vien tajā vietā, kurā atrodas skripts, kurā tiek includēts šis uploadošanas pasākums, nav tāda direktorija "files" Paldies Aleksej, starpc mani ar sauc Aleksejs ;D. Visu sametu vienā mapē itkā tgd nemet erorus :) Quote Link to comment Share on other sites More sharing options...
2easy Posted December 28, 2009 Report Share Posted December 28, 2009 relatīvajam path vajadzētu būt ok, ja tajā vietā ir attiecīgais folderis neiedomājos, ka viņš nečeko pathus... bet tik iemet kkur :D 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.