Home » HTTP » HTTP_Upload » Bug #1650
incompatibility php4.2.2 php4.3.7
Details
| Submitted | 2004-06-15 20:17 UTC |
|---|---|
| From | schouwerwou at postmaster dot co dot uk |
| Assigned | antonio |
| Status | Closed |
| Package | HTTP_Upload |
| PHP Version | 4.2.2 |
| OS | Linux 2.4.18-686 |
| Roadmaps | (Not assigned) |
Comments
[2004-06-15 20:17 UTC] schouwerwou at postmaster dot co dot uk
Description:
------------
An upload script produced: E_FAIL_MOVE on linux php 4.1.2, but everything worked perfect on php 4.3.7. (upload v. 1.23)
I fixed it by changing:
---------------------------------------------------
// original, line 578
if (!@copy($this->upload['tmp_name'], $name_dest)) {
return $this->raiseError('E_FAIL_MOVE');
}
---------------------------------------------------
to
---------------------------------------------------
// fix
if (!move_uploaded_file($this->upload['tmp_name'], $name_dest)){
return $this->raiseError('E_FAIL_MOVE');
}
---------------------------------------------------
Reproduce code:
---------------
// form.php
<form action="upload.php" METHOD="post" ENCTYPE="multipart/form-data">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" size=40>
<input type="submit" value="Verstuur bestand">
</form>
// upload.php
function newUpload(){
ini_set("include_path","/pathTo/PEAR/");
ini_set("upload_max_filesize","16M");
ini_set("post_max_size","16M");
require 'HTTP/Upload.php';
$upload = new http_upload('en');
$file = $upload->getFiles('userfile'); // edited
if (PEAR::isError($file)) {
$msg = $file->getMessage();
return $msg;
}
if ($file->isValid()) {
$dest_dir = './documenten';
$file->setName('safe');
$dest_name = $file->moveTo($dest_dir);
if (PEAR::isError($dest_name)) {
$msg = $dest_name->getMessage();
}
else {
$real = $file->getProp('real');
$msg = "Uploaded $real as $dest_name in $dest_dir";
}
}
elseif ($file->isMissing()) {
$msg = "No file selected\n";
}
elseif ($file->isError()) {
$msg = $file->errorMsg();
}
if($msg) {
return $msg;
}
else {
return "yes!";
}
}
if($HTTP_POST_FILES){
newUpload();
}
Expected result:
----------------
return yes!
Actual result:
--------------
Upload Error: E_FAIL_MOVE!
[2004-06-16 20:02 UTC] schouwerwou at postmaster dot co dot uk
Just one thing, it is perhaps consistent to use a @ with functions as you already handle the errors.
if (!move_uploaded_file($this->upload['tmp_name'], $name_dest))
if (!@move_uploaded_file($this->upload['tmp_name'], $name_dest))
Keep the good work! :)