sejf83 Posted August 24, 2006 Share Posted August 24, 2006 I am migrating an app to a new server and I'm having trouble getting the move_uploaded_file function to work on the new server.I did a print_r($_FILES) and I know the file to be uploaded is valid and is in the max_upload_size limit. However, move_uploaded_file() returns false with no error message and I can't figure out why.Here is a link to my phpinfo();http://www.ucl.ac.uk/eastman/nutrident/check.phpAnd here is the pertinent code...php:$destdir = 'filestore/';$fileNameArray = explode(".",$_FILES["userfile"]["name"]);$fileBase = $fileNameArray[0];$ext = $fileNameArray[1];$destfile = $destdir.$fileBase.".".$ext;switch($_FILES["userfile"]["error"]) { case 0: if(move_uploaded_file($_FILES["userfile"]["tmp_name"], $destfile)) { //Change the file permissions chmod($destfile, 0755); } else $_SESSION["uploadError"] = "<span>Upload error!</span>"; break; case 1: $_SESSION["uploadError"] = "<span>Max size exceeded. Please upload a smaller file.</span>"; break; case 2: case 3: $_SESSION["uploadError"] = "<span>File Upload Incomplete! Please Try Again.</span>\n"; break; case 4: $_SESSION["uploadError"] = "<span>Please select a valid file.</span>\n"; break; }$_SESSION["uploadError"] always returns "Upload Error!".Is there something wrong with my php.ini?Thanks. Quote Link to comment Share on other sites More sharing options...
blunt Posted August 24, 2006 Share Posted August 24, 2006 is your error reporting set to E_ALL ? Quote Link to comment Share on other sites More sharing options...
sejf83 Posted August 24, 2006 Author Share Posted August 24, 2006 It is set to 4. Quote Link to comment Share on other sites More sharing options...
True`Logic Posted August 24, 2006 Share Posted August 24, 2006 try @copy().. your form:[code]<form method=POST action=test2.php enctype=multipart/form-data><p>File to upload:<br><table border=0 cellspacing=0 cellpadding=0><tr><td colspan=2><input type=file name=img size=20></td></tr><tr><td><textarea name="comment" cols=15 rows=5></textarea></td><td>Image Comments</td></tr><tr><td><input type="submit" name="submit" value="Upload"></td><td><input type=reset value=Clear></td></tr></table></form><br><hr><?phpif(file_exists("uploaded_files.html")) {echo "<a href=uploaded_files.html>Uploaded Files</a>";}?>[/code]test2.php:[code]<?php$a = strstr($img_name, ".");if ($a != ".jpg" && $a != ".gif") {echo "only formats accepted are .jpg and .gif!<input type='button' value='back' onclick='history.go(-1)'>";} elseif ($img_size > 153600) {echo "Cannot upload above a 150kb file (153600 bytes)<input type='button' value='back' onclick='history.go(-1)'>";} else {$log = "";$abpath = "./";function GetFile() {$num = 0;while(file_exists($num . ".jpg")){$num++;}return $num;}$moo = GetFile();@copy($img, "$abpath/" . $moo . ".jpg") or $log .= "Couldn't copy file to server<br><input type='button' value='back' onclick='history.go(-1)'>";if (file_exists("$abpath/" . $moo . ".jpg")) {$log .= "File was uploaded<br><input type='button' value='back' onclick='history.go(-1)'>";$fp = fopen($moo . ".txt", "a");fwrite($fp, $_POST["comment"]);fclose($fp);/* $filename = "uploaded_files.html";$fp = fopen($filename, "a");fwrite($fp, "<hr>Image Number: #" . $moo . "<br><a href=$abpath/" . $moo . ".jpg><img src='$abpath/" . $moo . "' width=90 height=90 title='click for fullsize'></a><br>". $_POST["comment"] . "<br>");fclose($fp);*/}echo $log;}?>[/code]seems easier ^.^hope this helped - TL 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.