Jump to content

File uploads not working...


sejf83

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

http://www.ucl.ac.uk/eastman/nutrident/check.php

And 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.
Link to comment
Share on other sites

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>
<?php
if(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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.