Jump to content

Archived

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

sejf83

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

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.

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:
[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

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.