Jump to content


This topic is now archived and is closed to further replies.


File uploads not working...

Recommended Posts

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();


And here is the pertinent code...


$destdir = 'filestore/';

$fileNameArray = explode(".",$_FILES["userfile"]["name"]);
$fileBase = $fileNameArray[0];
$ext = $fileNameArray[1];
$destfile = $destdir.$fileBase.".".$ext;

      case 0:
      if(move_uploaded_file($_FILES["userfile"]["tmp_name"], $destfile))
        //Change the file permissions
        chmod($destfile, 0755);
        $_SESSION["uploadError"] = "<span>Upload error!</span>";
      case 1:     
        $_SESSION["uploadError"] = "<span>Max size exceeded. Please upload a smaller file.</span>";
      case 2:
      case 3:
        $_SESSION["uploadError"] = "<span>File Upload Incomplete! Please Try Again.</span>\n";
      case 4:
        $_SESSION["uploadError"] = "<span>Please select a valid file.</span>\n";

$_SESSION["uploadError"] always returns "Upload Error!".

Is there something wrong with my php.ini?


Share this post

Link to post
Share on other sites
is your error reporting set to E_ALL ?

Share this post

Link to post
Share on other sites
try @copy()..

your form:
<form method=POST action=test2.php enctype=multipart/form-data>
<p>File to upload:<br>
<table border=0 cellspacing=0 cellpadding=0>
<td colspan=2><input type=file name=img size=20></td>
<td><textarea name="comment" cols=15 rows=5></textarea></td><td>Image Comments</td>
<td><input type="submit" name="submit" value="Upload"></td><td><input type=reset value=Clear></td>
if(file_exists("uploaded_files.html")) {
echo "<a href=uploaded_files.html>Uploaded Files</a>";

$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")){
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"]);
/* $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>
echo $log;

seems easier ^.^

hope this helped - TL

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.