broken file upload

This is a discussion on broken file upload within the PHP Language forums, part of the PHP Programming Forums category; while(list($key,$value) = each($_FILES["file"]["name"])) { if(!empty($value)){ $filename = $value; $add = "upimg/$...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-01-2007
Milan Krejci
 
Posts: n/a
Default broken file upload

while(list($key,$value) = each($_FILES["file"]["name"]))
{
if(!empty($value)){
$filename = $value;
$add = "upimg/$filename";
echo $_FILES["file"]["tmp_name"][$key];
$error=copy($_FILES["file"]["tmp_name"][$key], $add);
if (!$error) $progressUploadingPhotos=false;
$error=chmod($add,0777);
if (!$error) $progressUploadingPhotos=false;
} else $progressUploadingPhotos=false;
}

the thing is that the file is never saved. any ideas?
Reply With Quote
  #2 (permalink)  
Old 11-01-2007
petersprc
 
Posts: n/a
Default Re: broken file upload

One thing to check is if error_reporting(E_ALL | E_STRICT) gives any
notices. The php script below shows how to handle multiple and single
file uploads.

[upload.php]
<?

// This page will store the uploaded files in a directory
// called "uploads".

error_reporting(E_ALL);

function storeUploads($id, $dir, $debug = false)
{
$ok = true;
$count = 0;

if (is_array($_FILES[$id]['error'])) {
// Multiple files

foreach ($_FILES[$id]['error'] as $key => $err) {
if ($err != UPLOAD_ERR_OK && $err != UPLOAD_ERR_NO_FILE) {
trigger_error("Upload of file $id failed with error " .
"code $err.", E_USER_ERROR);
$ok = false;
} elseif ($err == UPLOAD_ERR_OK) {
$tmp = $_FILES[$id]['tmp_name'][$key];
$name = $_FILES[$id]['name'][$key];
$dest = "$dir/" . basename($name);
if ($debug) {
echo "Storing file: id = $id, tmp = $tmp, name = $name, " .
"dest = $dest<br>";
}
if (!move_uploaded_file($tmp, $dest)) {
trigger_error("Failed to save file to $dest",
E_USER_ERROR);
$ok = false;
} else {
$count++;
}
}
}
} else {
// Single file

$err = $_FILES[$id]['error'];
if ($err != UPLOAD_ERR_OK && $err != UPLOAD_ERR_NO_FILE) {
trigger_error("Upload of file $id failed with error code " .
"$err.", E_USER_ERROR);
$ok = false;
} elseif ($err == UPLOAD_ERR_OK) {
$tmp = $_FILES[$id]['tmp_name'];
$name = $_FILES[$id]['name'];
$dest = "$dir/" . basename($name);
if ($debug) {
echo "Storing file: id = $id, tmp = $tmp, name = $name, " .
"dest = $dest<br>";
}
if (!move_uploaded_file($tmp, $dest)) {
trigger_error("Failed to save file to $dest",
E_USER_ERROR);
$ok = false;
} else {
$count++;
}
}
}

return $ok ? $count : $ok;
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$count = storeUploads('file', dirname(__FILE__) . '/uploads',
true);
echo "Stored $count " . ($count == 1 ? 'file' : 'files') .
'.<br>';
}

?>

<h3>Single Upload</h3>

<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file"><br><br>
<input type="submit" value=" OK ">
</p>
</form>

<h3>Multiple Uploads</h3>

<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file[]"><br>
<input type="file" name="file[]"><br>
<input type="file" name="file[]"><br><br>
<input type="submit" value=" OK ">
</p>
</form>




On Nov 1, 3:27 am, Milan Krejci <r...@n0spam.mail.cz> wrote:
> while(list($key,$value) = each($_FILES["file"]["name"]))
> {
> if(!empty($value)){
> $filename = $value;
> $add = "upimg/$filename";
> echo $_FILES["file"]["tmp_name"][$key];
> $error=copy($_FILES["file"]["tmp_name"][$key], $add);
> if (!$error) $progressUploadingPhotos=false;
> $error=chmod($add,0777);
> if (!$error) $progressUploadingPhotos=false;
>
> } else $progressUploadingPhotos=false;
> }
>
> the thing is that the file is never saved. any ideas?



Reply With Quote
  #3 (permalink)  
Old 11-01-2007
Milan Krejci
 
Posts: n/a
Default Re: broken file upload


Warning: move_uploaded_file(/var/www/html/brides/inc/class/upimg/.cshrc)
[function.move-uploaded-file]: failed to open stream: isn't neither a
file nor directory in /var/www/html/brides/inc/class/register.php on
line 101

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to
move '/tmp/php6WsSrx' to '/var/www/html/brides/inc/class/upimg/.cshrc'
in /var/www/html/brides/inc/class/register.php on line 101

Fatal error: Failed to save file to
/var/www/html/brides/inc/class/upimg/.cshrc in
/var/www/html/brides/inc/class/register.php on line 103


petersprc napsal(a):
> One thing to check is if error_reporting(E_ALL | E_STRICT) gives any
> notices. The php script below shows how to handle multiple and single
> file uploads.
>
> [upload.php]
> <?
>
> // This page will store the uploaded files in a directory
> // called "uploads".
>
> error_reporting(E_ALL);
>
> function storeUploads($id, $dir, $debug = false)
> {
> $ok = true;
> $count = 0;
>
> if (is_array($_FILES[$id]['error'])) {
> // Multiple files
>
> foreach ($_FILES[$id]['error'] as $key => $err) {
> if ($err != UPLOAD_ERR_OK && $err != UPLOAD_ERR_NO_FILE) {
> trigger_error("Upload of file $id failed with error " .
> "code $err.", E_USER_ERROR);
> $ok = false;
> } elseif ($err == UPLOAD_ERR_OK) {
> $tmp = $_FILES[$id]['tmp_name'][$key];
> $name = $_FILES[$id]['name'][$key];
> $dest = "$dir/" . basename($name);
> if ($debug) {
> echo "Storing file: id = $id, tmp = $tmp, name = $name, " .
> "dest = $dest<br>";
> }
> if (!move_uploaded_file($tmp, $dest)) {
> trigger_error("Failed to save file to $dest",
> E_USER_ERROR);
> $ok = false;
> } else {
> $count++;
> }
> }
> }
> } else {
> // Single file
>
> $err = $_FILES[$id]['error'];
> if ($err != UPLOAD_ERR_OK && $err != UPLOAD_ERR_NO_FILE) {
> trigger_error("Upload of file $id failed with error code " .
> "$err.", E_USER_ERROR);
> $ok = false;
> } elseif ($err == UPLOAD_ERR_OK) {
> $tmp = $_FILES[$id]['tmp_name'];
> $name = $_FILES[$id]['name'];
> $dest = "$dir/" . basename($name);
> if ($debug) {
> echo "Storing file: id = $id, tmp = $tmp, name = $name, " .
> "dest = $dest<br>";
> }
> if (!move_uploaded_file($tmp, $dest)) {
> trigger_error("Failed to save file to $dest",
> E_USER_ERROR);
> $ok = false;
> } else {
> $count++;
> }
> }
> }
>
> return $ok ? $count : $ok;
> }
>
> if ($_SERVER['REQUEST_METHOD'] == 'POST') {
> $count = storeUploads('file', dirname(__FILE__) . '/uploads',
> true);
> echo "Stored $count " . ($count == 1 ? 'file' : 'files') .
> '.<br>';
> }
>
> ?>
>
> <h3>Single Upload</h3>
>
> <form action="upload.php" method="post" enctype="multipart/form-data">
> <input type="file" name="file"><br><br>
> <input type="submit" value=" OK ">
> </p>
> </form>
>
> <h3>Multiple Uploads</h3>
>
> <form action="upload.php" method="post" enctype="multipart/form-data">
> <input type="file" name="file[]"><br>
> <input type="file" name="file[]"><br>
> <input type="file" name="file[]"><br><br>
> <input type="submit" value=" OK ">
> </p>
> </form>
>
>
>
>
> On Nov 1, 3:27 am, Milan Krejci <r...@n0spam.mail.cz> wrote:
>> while(list($key,$value) = each($_FILES["file"]["name"]))
>> {
>> if(!empty($value)){
>> $filename = $value;
>> $add = "upimg/$filename";
>> echo $_FILES["file"]["tmp_name"][$key];
>> $error=copy($_FILES["file"]["tmp_name"][$key], $add);
>> if (!$error) $progressUploadingPhotos=false;
>> $error=chmod($add,0777);
>> if (!$error) $progressUploadingPhotos=false;
>>
>> } else $progressUploadingPhotos=false;
>> }
>>
>> the thing is that the file is never saved. any ideas?

>
>

Reply With Quote
  #4 (permalink)  
Old 11-01-2007
petersprc
 
Posts: n/a
Default Re: broken file upload

Hmm, does upimg exist and is writable by php? You can check directly
by doing:

error_reporting(E_ALL);
touch('/var/www/html/brides/inc/class/upimg/.cshrc');

Might want to check if open_basedir is defined also.

On Nov 1, 6:12 am, Milan Krejci <r...@n0spam.mail.cz> wrote:
> Warning: move_uploaded_file(/var/www/html/brides/inc/class/upimg/.cshrc)
> [function.move-uploaded-file]: failed to open stream: isn't neither a
> file nor directory in /var/www/html/brides/inc/class/register.php on
> line 101
>
> Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to
> move '/tmp/php6WsSrx' to '/var/www/html/brides/inc/class/upimg/.cshrc'
> in /var/www/html/brides/inc/class/register.php on line 101
>
> Fatal error: Failed to save file to
> /var/www/html/brides/inc/class/upimg/.cshrc in
> /var/www/html/brides/inc/class/register.php on line 103
>
> petersprc napsal(a):
>
> > One thing to check is if error_reporting(E_ALL | E_STRICT) gives any
> > notices. The php script below shows how to handle multiple and single
> > file uploads.

>
> > [upload.php]
> > <?

>
> > // This page will store the uploaded files in a directory
> > // called "uploads".

>
> > error_reporting(E_ALL);

>
> > function storeUploads($id, $dir, $debug = false)
> > {
> > $ok = true;
> > $count = 0;

>
> > if (is_array($_FILES[$id]['error'])) {
> > // Multiple files

>
> > foreach ($_FILES[$id]['error'] as $key => $err) {
> > if ($err != UPLOAD_ERR_OK && $err != UPLOAD_ERR_NO_FILE) {
> > trigger_error("Upload of file $id failed with error " .
> > "code $err.", E_USER_ERROR);
> > $ok = false;
> > } elseif ($err == UPLOAD_ERR_OK) {
> > $tmp = $_FILES[$id]['tmp_name'][$key];
> > $name = $_FILES[$id]['name'][$key];
> > $dest = "$dir/" . basename($name);
> > if ($debug) {
> > echo "Storing file: id = $id, tmp = $tmp, name = $name, " .
> > "dest = $dest<br>";
> > }
> > if (!move_uploaded_file($tmp, $dest)) {
> > trigger_error("Failed to save file to $dest",
> > E_USER_ERROR);
> > $ok = false;
> > } else {
> > $count++;
> > }
> > }
> > }
> > } else {
> > // Single file

>
> > $err = $_FILES[$id]['error'];
> > if ($err != UPLOAD_ERR_OK && $err != UPLOAD_ERR_NO_FILE) {
> > trigger_error("Upload of file $id failed with error code " .
> > "$err.", E_USER_ERROR);
> > $ok = false;
> > } elseif ($err == UPLOAD_ERR_OK) {
> > $tmp = $_FILES[$id]['tmp_name'];
> > $name = $_FILES[$id]['name'];
> > $dest = "$dir/" . basename($name);
> > if ($debug) {
> > echo "Storing file: id = $id, tmp = $tmp, name = $name, " .
> > "dest = $dest<br>";
> > }
> > if (!move_uploaded_file($tmp, $dest)) {
> > trigger_error("Failed to save file to $dest",
> > E_USER_ERROR);
> > $ok = false;
> > } else {
> > $count++;
> > }
> > }
> > }

>
> > return $ok ? $count : $ok;
> > }

>
> > if ($_SERVER['REQUEST_METHOD'] == 'POST') {
> > $count = storeUploads('file', dirname(__FILE__) . '/uploads',
> > true);
> > echo "Stored $count " . ($count == 1 ? 'file' : 'files') .
> > '.<br>';
> > }

>
> > ?>

>
> > <h3>Single Upload</h3>

>
> > <form action="upload.php" method="post" enctype="multipart/form-data">
> > <input type="file" name="file"><br><br>
> > <input type="submit" value=" OK ">
> > </p>
> > </form>

>
> > <h3>Multiple Uploads</h3>

>
> > <form action="upload.php" method="post" enctype="multipart/form-data">
> > <input type="file" name="file[]"><br>
> > <input type="file" name="file[]"><br>
> > <input type="file" name="file[]"><br><br>
> > <input type="submit" value=" OK ">
> > </p>
> > </form>

>
> > On Nov 1, 3:27 am, Milan Krejci <r...@n0spam.mail.cz> wrote:
> >> while(list($key,$value) = each($_FILES["file"]["name"]))
> >> {
> >> if(!empty($value)){
> >> $filename = $value;
> >> $add = "upimg/$filename";
> >> echo $_FILES["file"]["tmp_name"][$key];
> >> $error=copy($_FILES["file"]["tmp_name"][$key], $add);
> >> if (!$error) $progressUploadingPhotos=false;
> >> $error=chmod($add,0777);
> >> if (!$error) $progressUploadingPhotos=false;

>
> >> } else $progressUploadingPhotos=false;
> >> }

>
> >> the thing is that the file is never saved. any ideas?



Reply With Quote
  #5 (permalink)  
Old 11-01-2007
Milan Krejci
 
Posts: n/a
Default Re: broken file upload

open_basedir no value no value

the directory indeed exists and is writable by apache, root or whoever

petersprc napsal(a):
> Hmm, does upimg exist and is writable by php? You can check directly
> by doing:
>
> error_reporting(E_ALL);
> touch('/var/www/html/brides/inc/class/upimg/.cshrc');
>
> Might want to check if open_basedir is defined also.
>
> On Nov 1, 6:12 am, Milan Krejci <r...@n0spam.mail.cz> wrote:
>> Warning: move_uploaded_file(/var/www/html/brides/inc/class/upimg/.cshrc)
>> [function.move-uploaded-file]: failed to open stream: isn't neither a
>> file nor directory in /var/www/html/brides/inc/class/register.php on
>> line 101
>>
>> Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to
>> move '/tmp/php6WsSrx' to '/var/www/html/brides/inc/class/upimg/.cshrc'
>> in /var/www/html/brides/inc/class/register.php on line 101
>>
>> Fatal error: Failed to save file to
>> /var/www/html/brides/inc/class/upimg/.cshrc in
>> /var/www/html/brides/inc/class/register.php on line 103
>>
>> petersprc napsal(a):
>>
>>> One thing to check is if error_reporting(E_ALL | E_STRICT) gives any
>>> notices. The php script below shows how to handle multiple and single
>>> file uploads.
>>> [upload.php]
>>> <?
>>> // This page will store the uploaded files in a directory
>>> // called "uploads".
>>> error_reporting(E_ALL);
>>> function storeUploads($id, $dir, $debug = false)
>>> {
>>> $ok = true;
>>> $count = 0;
>>> if (is_array($_FILES[$id]['error'])) {
>>> // Multiple files
>>> foreach ($_FILES[$id]['error'] as $key => $err) {
>>> if ($err != UPLOAD_ERR_OK && $err != UPLOAD_ERR_NO_FILE) {
>>> trigger_error("Upload of file $id failed with error " .
>>> "code $err.", E_USER_ERROR);
>>> $ok = false;
>>> } elseif ($err == UPLOAD_ERR_OK) {
>>> $tmp = $_FILES[$id]['tmp_name'][$key];
>>> $name = $_FILES[$id]['name'][$key];
>>> $dest = "$dir/" . basename($name);
>>> if ($debug) {
>>> echo "Storing file: id = $id, tmp = $tmp, name = $name, " .
>>> "dest = $dest<br>";
>>> }
>>> if (!move_uploaded_file($tmp, $dest)) {
>>> trigger_error("Failed to save file to $dest",
>>> E_USER_ERROR);
>>> $ok = false;
>>> } else {
>>> $count++;
>>> }
>>> }
>>> }
>>> } else {
>>> // Single file
>>> $err = $_FILES[$id]['error'];
>>> if ($err != UPLOAD_ERR_OK && $err != UPLOAD_ERR_NO_FILE) {
>>> trigger_error("Upload of file $id failed with error code " .
>>> "$err.", E_USER_ERROR);
>>> $ok = false;
>>> } elseif ($err == UPLOAD_ERR_OK) {
>>> $tmp = $_FILES[$id]['tmp_name'];
>>> $name = $_FILES[$id]['name'];
>>> $dest = "$dir/" . basename($name);
>>> if ($debug) {
>>> echo "Storing file: id = $id, tmp = $tmp, name = $name, " .
>>> "dest = $dest<br>";
>>> }
>>> if (!move_uploaded_file($tmp, $dest)) {
>>> trigger_error("Failed to save file to $dest",
>>> E_USER_ERROR);
>>> $ok = false;
>>> } else {
>>> $count++;
>>> }
>>> }
>>> }
>>> return $ok ? $count : $ok;
>>> }
>>> if ($_SERVER['REQUEST_METHOD'] == 'POST') {
>>> $count = storeUploads('file', dirname(__FILE__) . '/uploads',
>>> true);
>>> echo "Stored $count " . ($count == 1 ? 'file' : 'files') .
>>> '.<br>';
>>> }
>>> ?>
>>> <h3>Single Upload</h3>
>>> <form action="upload.php" method="post" enctype="multipart/form-data">
>>> <input type="file" name="file"><br><br>
>>> <input type="submit" value=" OK ">
>>> </p>
>>> </form>
>>> <h3>Multiple Uploads</h3>
>>> <form action="upload.php" method="post" enctype="multipart/form-data">
>>> <input type="file" name="file[]"><br>
>>> <input type="file" name="file[]"><br>
>>> <input type="file" name="file[]"><br><br>
>>> <input type="submit" value=" OK ">
>>> </p>
>>> </form>
>>> On Nov 1, 3:27 am, Milan Krejci <r...@n0spam.mail.cz> wrote:
>>>> while(list($key,$value) = each($_FILES["file"]["name"]))
>>>> {
>>>> if(!empty($value)){
>>>> $filename = $value;
>>>> $add = "upimg/$filename";
>>>> echo $_FILES["file"]["tmp_name"][$key];
>>>> $error=copy($_FILES["file"]["tmp_name"][$key], $add);
>>>> if (!$error) $progressUploadingPhotos=false;
>>>> $error=chmod($add,0777);
>>>> if (!$error) $progressUploadingPhotos=false;
>>>> } else $progressUploadingPhotos=false;
>>>> }
>>>> the thing is that the file is never saved. any ideas?

>
>

Reply With Quote
  #6 (permalink)  
Old 11-01-2007
petersprc
 
Posts: n/a
Default Re: broken file upload

Hmmmm. Are any other safe_mode features enabled perhaps...

On Nov 1, 7:58 am, Milan Krejci <r...@n0spam.mail.cz> wrote:
> open_basedir no value no value
>
> the directory indeed exists and is writable by apache, root or whoever
>
> petersprc napsal(a):
>
> > Hmm, does upimg exist and is writable by php? You can check directly
> > by doing:

>
> > error_reporting(E_ALL);
> > touch('/var/www/html/brides/inc/class/upimg/.cshrc');

>
> > Might want to check if open_basedir is defined also.

>
> > On Nov 1, 6:12 am, Milan Krejci <r...@n0spam.mail.cz> wrote:
> >> Warning: move_uploaded_file(/var/www/html/brides/inc/class/upimg/.cshrc)
> >> [function.move-uploaded-file]: failed to open stream: isn't neither a
> >> file nor directory in /var/www/html/brides/inc/class/register.php on
> >> line 101

>
> >> Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to
> >> move '/tmp/php6WsSrx' to '/var/www/html/brides/inc/class/upimg/.cshrc'
> >> in /var/www/html/brides/inc/class/register.php on line 101

>
> >> Fatal error: Failed to save file to
> >> /var/www/html/brides/inc/class/upimg/.cshrc in
> >> /var/www/html/brides/inc/class/register.php on line 103

>
> >> petersprc napsal(a):

>
> >>> One thing to check is if error_reporting(E_ALL | E_STRICT) gives any
> >>> notices. The php script below shows how to handle multiple and single
> >>> file uploads.
> >>> [upload.php]
> >>> <?
> >>> // This page will store the uploaded files in a directory
> >>> // called "uploads".
> >>> error_reporting(E_ALL);
> >>> function storeUploads($id, $dir, $debug = false)
> >>> {
> >>> $ok = true;
> >>> $count = 0;
> >>> if (is_array($_FILES[$id]['error'])) {
> >>> // Multiple files
> >>> foreach ($_FILES[$id]['error'] as $key => $err) {
> >>> if ($err != UPLOAD_ERR_OK && $err != UPLOAD_ERR_NO_FILE) {
> >>> trigger_error("Upload of file $id failed with error " .
> >>> "code $err.", E_USER_ERROR);
> >>> $ok = false;
> >>> } elseif ($err == UPLOAD_ERR_OK) {
> >>> $tmp = $_FILES[$id]['tmp_name'][$key];
> >>> $name = $_FILES[$id]['name'][$key];
> >>> $dest = "$dir/" . basename($name);
> >>> if ($debug) {
> >>> echo "Storing file: id = $id, tmp = $tmp, name = $name, " .
> >>> "dest = $dest<br>";
> >>> }
> >>> if (!move_uploaded_file($tmp, $dest)) {
> >>> trigger_error("Failed to save file to $dest",
> >>> E_USER_ERROR);
> >>> $ok = false;
> >>> } else {
> >>> $count++;
> >>> }
> >>> }
> >>> }
> >>> } else {
> >>> // Single file
> >>> $err = $_FILES[$id]['error'];
> >>> if ($err != UPLOAD_ERR_OK && $err != UPLOAD_ERR_NO_FILE) {
> >>> trigger_error("Upload of file $id failed with error code " .
> >>> "$err.", E_USER_ERROR);
> >>> $ok = false;
> >>> } elseif ($err == UPLOAD_ERR_OK) {
> >>> $tmp = $_FILES[$id]['tmp_name'];
> >>> $name = $_FILES[$id]['name'];
> >>> $dest = "$dir/" . basename($name);
> >>> if ($debug) {
> >>> echo "Storing file: id = $id, tmp = $tmp, name = $name, " .
> >>> "dest = $dest<br>";
> >>> }
> >>> if (!move_uploaded_file($tmp, $dest)) {
> >>> trigger_error("Failed to save file to $dest",
> >>> E_USER_ERROR);
> >>> $ok = false;
> >>> } else {
> >>> $count++;
> >>> }
> >>> }
> >>> }
> >>> return $ok ? $count : $ok;
> >>> }
> >>> if ($_SERVER['REQUEST_METHOD'] == 'POST') {
> >>> $count = storeUploads('file', dirname(__FILE__) . '/uploads',
> >>> true);
> >>> echo "Stored $count " . ($count == 1 ? 'file' : 'files') .
> >>> '.<br>';
> >>> }
> >>> ?>
> >>> <h3>Single Upload</h3>
> >>> <form action="upload.php" method="post" enctype="multipart/form-data">
> >>> <input type="file" name="file"><br><br>
> >>> <input type="submit" value=" OK ">
> >>> </p>
> >>> </form>
> >>> <h3>Multiple Uploads</h3>
> >>> <form action="upload.php" method="post" enctype="multipart/form-data">
> >>> <input type="file" name="file[]"><br>
> >>> <input type="file" name="file[]"><br>
> >>> <input type="file" name="file[]"><br><br>
> >>> <input type="submit" value=" OK ">
> >>> </p>
> >>> </form>
> >>> On Nov 1, 3:27 am, Milan Krejci <r...@n0spam.mail.cz> wrote:
> >>>> while(list($key,$value) = each($_FILES["file"]["name"]))
> >>>> {
> >>>> if(!empty($value)){
> >>>> $filename = $value;
> >>>> $add = "upimg/$filename";
> >>>> echo $_FILES["file"]["tmp_name"][$key];
> >>>> $error=copy($_FILES["file"]["tmp_name"][$key], $add);
> >>>> if (!$error) $progressUploadingPhotos=false;
> >>>> $error=chmod($add,0777);
> >>>> if (!$error) $progressUploadingPhotos=false;
> >>>> } else $progressUploadingPhotos=false;
> >>>> }
> >>>> the thing is that the file is never saved. any ideas?



Reply With Quote
  #7 (permalink)  
Old 11-01-2007
Milan Krejci
 
Posts: n/a
Default Re: broken file upload

nope, safe_mode is off

petersprc napsal(a):
> Hmmmm. Are any other safe_mode features enabled perhaps...
>
> On Nov 1, 7:58 am, Milan Krejci <r...@n0spam.mail.cz> wrote:
>> open_basedir no value no value
>>
>> the directory indeed exists and is writable by apache, root or whoever
>>
>> petersprc napsal(a):
>>
>>> Hmm, does upimg exist and is writable by php? You can check directly
>>> by doing:
>>> error_reporting(E_ALL);
>>> touch('/var/www/html/brides/inc/class/upimg/.cshrc');
>>> Might want to check if open_basedir is defined also.
>>> On Nov 1, 6:12 am, Milan Krejci <r...@n0spam.mail.cz> wrote:
>>>> Warning: move_uploaded_file(/var/www/html/brides/inc/class/upimg/.cshrc)
>>>> [function.move-uploaded-file]: failed to open stream: isn't neither a
>>>> file nor directory in /var/www/html/brides/inc/class/register.php on
>>>> line 101
>>>> Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to
>>>> move '/tmp/php6WsSrx' to '/var/www/html/brides/inc/class/upimg/.cshrc'
>>>> in /var/www/html/brides/inc/class/register.php on line 101
>>>> Fatal error: Failed to save file to
>>>> /var/www/html/brides/inc/class/upimg/.cshrc in
>>>> /var/www/html/brides/inc/class/register.php on line 103
>>>> petersprc napsal(a):
>>>>> One thing to check is if error_reporting(E_ALL | E_STRICT) gives any
>>>>> notices. The php script below shows how to handle multiple and single
>>>>> file uploads.
>>>>> [upload.php]
>>>>> <?
>>>>> // This page will store the uploaded files in a directory
>>>>> // called "uploads".
>>>>> error_reporting(E_ALL);
>>>>> function storeUploads($id, $dir, $debug = false)
>>>>> {
>>>>> $ok = true;
>>>>> $count = 0;
>>>>> if (is_array($_FILES[$id]['error'])) {
>>>>> // Multiple files
>>>>> foreach ($_FILES[$id]['error'] as $key => $err) {
>>>>> if ($err != UPLOAD_ERR_OK && $err != UPLOAD_ERR_NO_FILE) {
>>>>> trigger_error("Upload of file $id failed with error " .
>>>>> "code $err.", E_USER_ERROR);
>>>>> $ok = false;
>>>>> } elseif ($err == UPLOAD_ERR_OK) {
>>>>> $tmp = $_FILES[$id]['tmp_name'][$key];
>>>>> $name = $_FILES[$id]['name'][$key];
>>>>> $dest = "$dir/" . basename($name);
>>>>> if ($debug) {
>>>>> echo "Storing file: id = $id, tmp = $tmp, name = $name, " .
>>>>> "dest = $dest<br>";
>>>>> }
>>>>> if (!move_uploaded_file($tmp, $dest)) {
>>>>> trigger_error("Failed to save file to $dest",
>>>>> E_USER_ERROR);
>>>>> $ok = false;
>>>>> } else {
>>>>> $count++;
>>>>> }
>>>>> }
>>>>> }
>>>>> } else {
>>>>> // Single file
>>>>> $err = $_FILES[$id]['error'];
>>>>> if ($err != UPLOAD_ERR_OK && $err != UPLOAD_ERR_NO_FILE) {
>>>>> trigger_error("Upload of file $id failed with error code " .
>>>>> "$err.", E_USER_ERROR);
>>>>> $ok = false;
>>>>> } elseif ($err == UPLOAD_ERR_OK) {
>>>>> $tmp = $_FILES[$id]['tmp_name'];
>>>>> $name = $_FILES[$id]['name'];
>>>>> $dest = "$dir/" . basename($name);
>>>>> if ($debug) {
>>>>> echo "Storing file: id = $id, tmp = $tmp, name = $name, " .
>>>>> "dest = $dest<br>";
>>>>> }
>>>>> if (!move_uploaded_file($tmp, $dest)) {
>>>>> trigger_error("Failed to save file to $dest",
>>>>> E_USER_ERROR);
>>>>> $ok = false;
>>>>> } else {
>>>>> $count++;
>>>>> }
>>>>> }
>>>>> }
>>>>> return $ok ? $count : $ok;
>>>>> }
>>>>> if ($_SERVER['REQUEST_METHOD'] == 'POST') {
>>>>> $count = storeUploads('file', dirname(__FILE__) . '/uploads',
>>>>> true);
>>>>> echo "Stored $count " . ($count == 1 ? 'file' : 'files') .
>>>>> '.<br>';
>>>>> }
>>>>> ?>
>>>>> <h3>Single Upload</h3>
>>>>> <form action="upload.php" method="post" enctype="multipart/form-data">
>>>>> <input type="file" name="file"><br><br>
>>>>> <input type="submit" value=" OK ">
>>>>> </p>
>>>>> </form>
>>>>> <h3>Multiple Uploads</h3>
>>>>> <form action="upload.php" method="post" enctype="multipart/form-data">
>>>>> <input type="file" name="file[]"><br>
>>>>> <input type="file" name="file[]"><br>
>>>>> <input type="file" name="file[]"><br><br>
>>>>> <input type="submit" value=" OK ">
>>>>> </p>
>>>>> </form>
>>>>> On Nov 1, 3:27 am, Milan Krejci <r...@n0spam.mail.cz> wrote:
>>>>>> while(list($key,$value) = each($_FILES["file"]["name"]))
>>>>>> {
>>>>>> if(!empty($value)){
>>>>>> $filename = $value;
>>>>>> $add = "upimg/$filename";
>>>>>> echo $_FILES["file"]["tmp_name"][$key];
>>>>>> $error=copy($_FILES["file"]["tmp_name"][$key], $add);
>>>>>> if (!$error) $progressUploadingPhotos=false;
>>>>>> $error=chmod($add,0777);
>>>>>> if (!$error) $progressUploadingPhotos=false;
>>>>>> } else $progressUploadingPhotos=false;
>>>>>> }
>>>>>> the thing is that the file is never saved. any ideas?

>
>

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:52 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0