FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Need help: Error in Wordpress file





Animal
Hi all,

I recently upgraded to Wordpress 2.1 and everything seems to be working except my file uploads. When I try to upload a photo to my blog, I get an error saying that there is a problem with line 1879 of admin-functions.php

I have virtually no php knowledge at all, so I would appreciate any help with this. Despite looking for "extra whitespace" as suggested on the Wordpress forums, I can't seem to fix it. FRIH$ to the person who can do it for me Wink

Download the file here

Thanks for any input!
MrBlueSky
Can you copy/paste the error message here?
Animal
MrBlueSky wrote:
Can you copy/paste the error message here?

Sure:
Quote:
The uploaded file could not be moved to /home/animal/public_html/blog/wp-content/uploads/2007/02.
Warning: Cannot modify header information - headers already sent by (output started at /home/animal/public_html/blog/wp-admin/admin-functions.php:1879) in /home/animal/public_html/blog/wp-includes/functions.php on line 1219


I sourced the "whitespace" solution here but didn't find it to be much help.
hexkid
Quote:
The uploaded file could not be moved to /home/animal/public_html/blog/wp-content/uploads/2007/02.
Warning: Cannot modify header information - headers already sent by (output started at /home/animal/public_html/blog/wp-admin/admin-functions.php:1879) in /home/animal/public_html/blog/wp-includes/functions.php on line 1219


What's in .../wp-admin/admin-functions.php at lines 1870 to 1880?
MrBlueSky
Ah, I see. Now the question is in which file you (probably) have an extra whitespace.


-- edit --
Animal
Ok, the code is:
Code:
   } else {
      $number = '';
      $filename = str_replace( '#', '_', $file['name'] );
      $filename = str_replace( array( '\\', "'" ), '', $filename );
      if ( empty( $ext) )
         $ext = '';
      else
         $ext = ".$ext";
      while ( file_exists( $uploads['path'] . "/$filename" ) ) {
         if ( '' == "$number$ext" )
            $filename = $filename . ++$number . $ext;
         else
            $filename = str_replace( "$number$ext", ++$number . $ext, $filename );
      }
      $filename = str_replace( $ext, '', $filename );
      $filename = sanitize_title_with_dashes( $filename ) . $ext;
   }

   // Move the file to the uploads dir
   $new_file = $uploads['path'] . "/$filename";
   if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) )
      wp_die( printf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ));               <<<<<Line 1879.

   // Set correct file permissions
   $stat = stat( dirname( $new_file ));
   $perms = $stat['mode'] & 0000666;
   @ chmod( $new_file, $perms );

   // Compute the URL
   $url = $uploads['url'] . "/$filename";
   
   $return = apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ) );

   return $return;
}

I've highlighted line 1879 using "<<<<<Line 1879" - there was no whitespace after the final ";"
hexkid
Does the directory /home/animal/public_html/blog/wp-content/uploads/2007/02 exist [edit] and with the correct permissions?
Animal
hexkid wrote:
Does the directory /home/animal/public_html/blog/wp-content/uploads/2007/02 exist?

Yes Wink First thing I checked. I also changed the CHMOD of all the upload folders to 777, so it's not a permissions problem either.
hexkid
Hmmmmm ... try removing the "@" from line 1878

Code:
   if ( false === /*@*/ move_uploaded_file( $file['tmp_name'], $new_file ) )
      wp_die( printf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ));               <<<<<Line 1879.


Hopefully you will get a warning which may indicate why the move_ uploaded_ file() function is returning false.
Rhysige
mabye the php config doesnt allow uploading?
Animal
Ohh... new error:

Quote:
Warning: move_uploaded_file() [function.move-uploaded-file]: SAFE MODE Restriction in effect. The script whose uid is 32384 is not allowed to access /home/animal/public_html/blog/wp-content/uploads/2007/02 owned by uid 99 in /home/animal/public_html/blog/wp-admin/admin-functions.php on line 1878
The uploaded file could not be moved to /home/animal/public_html/blog/wp-content/uploads/2007/02.
Warning: Cannot modify header information - headers already sent by (output started at /home/animal/public_html/blog/wp-admin/admin-functions.php:1878) in /home/animal/public_html/blog/wp-includes/functions.php on line 1219


From what I could gather from the link you gave, php is checking that the input file is valid before it's transferred to the uploads directory? I tried renaming the file to "001.jpg" and it still didn't work.

Sorry, but I really can't do php at all! Any more suggestions? Eh?
hexkid
Ok ...

1) if you have files in the .../2007/02 directory, rename it to something else;
otherwise, just delete it Smile

2) put this script somewhere where you can run it from your browser
Code:
<?php
if (!mkdir('/home/animal/public_html/blog/wp-content/uploads/2007/02', 0711)) {
  echo 'Oops ... the script cannot create the directory';
} else {
  echo 'WooHoo! Word-Press should work now :)';
}
?>

This will create the directory with the user Apache runs under (uid 99)

3) run the script (maybe by going to http://www.animal.com/blog/gooddir.php ?)

4) if needed restore files from the directory created at 1)

5) test

6) if it worked, reinstate the "@" in line 1878 Smile


[Edit]???????????????????
Hmmm ... well ... err ... I mean the directory must belong to the same user (99 or 32384) that owns the script.

Either create the directory with Apache as above, or do it from wherever you upload scripts to the server.

Sorry Smile
hexkid
To know who owns the directory run this
Code:
<?php
echo '<pre>';
echo `ls -al /home/animal/public_html/blog/wp-content/uploads/2007`;
echo '</pre>';
?>



To know who owns the script run this
Code:
<?php
echo '<pre>';
echo `ls -al /home/animal/public_html/blog/wp-admin`;
echo '</pre>';
?>


Then make them belong to the same user Wink
Animal
hexkid wrote:
2) put this script somewhere where you can run it from your browser
Code:
<?php
if (!mkdir('/home/animal/public_html/blog/wp-content/uploads/2007/02', 0711)) {
  echo 'Oops ... the script cannot create the directory';
} else {
  echo 'WooHoo! Word-Press should work now :)';
}
?>

The script ran ok, but when I try to upload a new file, I get this error again:
Quote:
The uploaded file could not be moved to /home/animal/public_html/blog/wp-content/uploads/2007/02.
Warning: Cannot modify header information - headers already sent by (output started at /home/animal/public_html/blog/wp-admin/admin-functions.php:1879) in /home/animal/public_html/blog/wp-includes/functions.php on line 1219


hexkid wrote:
To know who owns the directory run this
Code:
<?php
echo '<pre>';
echo `ls -al /home/animal/public_html/blog/wp-content/uploads/2007`;
echo '</pre>';
?>

Unfortunately, this gave me the following error:
Quote:
Warning: shell_exec() [function.shell-exec]: Cannot execute using backquotes in Safe Mode in /home/animal/public_html/blog/who.php on line 3


Any more ideas?
hexkid
Hmmm ... stupid safe mode Wink

Try this
Code:
<?php
header('Content-Type: text/plain'); // I'm lazy

$stat1 = stat('/home/animal/public_html/blog/wp-content/uploads/2007/02');
$stat2 = stat('/home/animal/public_html/blog/wp-includes/functions.php');
echo "directory '.../02' belongs to {$stat1[4]}; the script 'functions.php' belongs to {$stat2[4]}.\n";
?>


If the result is different, you'll have to (re)create the directory with the same user as the functions.php script. Probably using the same interface you use to upload/create the script gets it done.
Animal
Hi, thanks again for all the help. The following message is (exactly) what I got:

Quote:
<br />
<b>Warning</b>: stat() [<a href='function.stat'>function.stat</a>]: SAFE MODE Restriction in effect. The script whose uid is 32384 is not allowed to access /home owned by uid 0 in <b>/home/animal/public_html/blog/who.php</b> on line <b>4</b><br />
<br />
<b>Warning</b>: stat() [<a href='function.stat'>function.stat</a>]: SAFE MODE Restriction in effect. The script whose uid is 32384 is not allowed to access /home owned by uid 0 in <b>/home/animal/public_html/blog/who.php</b> on line <b>5</b><br />
directory '.../02' belongs to ; the script 'functions.php' belongs to .


Does this mean I'd need to get the root user to create the directory for me? Eh?
hexkid
What about now?

Code:
<?php
header('Content-Type: text/plain'); // I'm lazy

$stat1 = stat('wp-content/uploads/2007/02');
$stat2 = stat('wp-includes/functions.php');
$stat3 = stat('who.php');
echo "directory '.../02' belongs to {$stat1[4]}; the script 'functions.php' belongs to {$stat2[4]}.\n\n";
echo "'who.php' belongs to {$stat3[4]}.\n"
?>


I have safe mode disabled in my test machine, so I apologize for all the trouble ... but I can't test my scripts with a configuration that matches your configuration; I'm doing the scripts on a trial-and-error basis.


No, you don't need to get the root user to create the directory for you.
Animal
Now we're getting somewhere!

Quote:
directory '.../02' belongs to 99; the script 'functions.php' belongs to 32384.

'who.php' belongs to 32384.


So... how do I create a file using UID 99 when my control panel creates files under the UID 32384?
hexkid
Can you delete the directory and recreate it from the control panel?
I think that will get it to belong to UID 32384. Try it (save previous contents) and rerun who.php
Animal
hexkid wrote:
Can you delete the directory and recreate it from the control panel?
I think that will get it to belong to UID 32384. Try it (save previous contents) and rerun who.php

I've already tried this and it doesn't work. Would I have to recreate the whole directory structure (ie. /blog/wp-content/uploads/2007/02/)? I have removed and recreated the /02/ directory only so far.
hexkid
Now I'm stumped Sad
Maybe it's time to contact your server administrator.

I believe it won't help to recreate the directory from below, but if it isn't too much trouble (not a lot of files to copy), it certainly doesn't hurt to try.
Animal
hexkid wrote:
Now I'm stumped Sad
Maybe it's time to contact your server administrator.

I believe it won't help to recreate the directory from below, but if it isn't too much trouble (not a lot of files to copy), it certainly doesn't hurt to try.

Ok... I'll see what the server admin has to say. Thanks very much for your help - it's most appreciated Very Happy
Animal
Ok... shame on me for the double-post here Embarassed However, I managed to solve my problem with a bit of lateral thinking (and didn't even have to call the server admin!)

I had a think about this problem, and realised that I could simply re-create admin-functions.php and functions.php manually using the control panel to give them the same UID as the target directory. I simply copied the contents of the original php files, re-named them "file.php.old" and created new, blank "file.php" files and pasted the content into them. Now all php files mentioned in the error are UID 32384 the same as the upload destination folder. Running the UID identifier now gives
Quote:
directory '.../02' belongs to 32384; the script 'functions.php' belongs to 32384.

'who.php' belongs to 32384.


Uploading files now works like a charm!

Thanks again to hexkid, Rhysige and MrBlueSky for all your input - I could never have worked out that this was simply a UID problem without you guys Very Happy
Related topics
Help with WordPress
Perl Script - Internal Error 404 File not found
Need help with Wordpress Please............
Replace the 404 ERROR PAGE
SQL error on my site
ERROR 404: File Not Found
Socket error = #10053..Anyone?
Need help fixing my php file
I can not access my error log file
HELP, reading text file from USB drive in visual basic
help with wordpress
Wordpress Help (finding a file)
ERROR: WordPress
HELP in .htaccess file modified
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.