I am using Drupal 4.6.5 with the core upload module and I'm just trying to get some basic upload functionality. I've configured this on other sites without any problem, but I can't seem to get uploads to work properly on this new one (different web server). Any help or suggestions would be greatly appreciated.

I am getting one of two results, depending on what I've done. On one hand, I can get the following message: "File copy failed: source file does not exist." If tmp is set to a relative path (files/tmp) in admin/settings, this is what happens. If I try just "tmp" as the relative path within the files directory, the directory is not recognized.

Or, if I get creative and use the full path for "tmp" Drupal thinks the file gets uploaded but I get a page cannot be found error!

Safe mode is not enabled, which is usually the cause of such problems (so I've seen in other forum posts).

I've tried using the full paths to the directories (the file seems to get uploaded to both tmp and "files" directories, but the URL for the file is wrong-- it includes the web url with the full path at the end and the file is not found).

I've tried putting tmp inside the files directory, in the install directory for Drupal, and in a directory above the public_html directory of my drupal install. I've even tried placing the files directory outside the public directory (just to experiment). With all of these attempts, I configured admin/settings to find the proper directories and ensured that they were permission friendly (777).

In all cases, I end up with jack as far as successfully uploaded files.

Well, what in the world is going on? There must be something about this webserver that is different than the other server I have had Drupal on? Any ideas? Any flashes of recognition? Thanks in advance for any suggestions. My web host is willing to work with me if an Apache or PHP setting is causing these issues...

Comments

bomarmonk’s picture

It seems that the file will copy into the "tmp" directory in the public_html directory, but it won't copy over to the files directory. Help! Any ideas what is causing this? It's like drupal is blind to its own uploads!

bomarmonk’s picture

Any ideas?

bomarmonk’s picture

My web host figured out the problem-- all file uploads were having problems because the directory permissions on up the chain needed different settings. My local directories allowed the proper write/read/execute access, but some of the directories I couldn't even see were causing issues. Thankfully the host was able to rectify the situation.

Here's an extended explanation from my provider, in case anyone runs into the same aggravating problem:
"There may or may not be a bug in PHP. The PHP guys are, imho, not real
nice at admitting this sort of thing is a bug. But it seems like
realpath() in the file.inc was failing to return anything. In reviewing
bugs.php.net, it looked like maybe if ANY parent directory is not readable
by the web server, then it returns "". I consider this a bug, personally,
because you don't normally need that to write a file in a child directory
you DO have permission for. But their mileage may differ."

developmenticon’s picture

I am getting the proble while uploading the file
Error-File copy failed: source file does not exist.

Any can help me

In advance thanks

allforabit’s picture

Here's a hack I used to fix the problem with realpath. I'm using the free space at awardspace.com and it's limited in some ways.

This worked for me anyway:

Open "file.inc" in the includes folder

Find and replace any instances of "realpath" with "realpath2"

And paste this function into the file:

function realpath2($path) {
$result = array();
// $pathA = preg_split('/[\/\\\]/', $path);
$pathA = explode('/', $path);
if (!$pathA[0])
$result[] = '';
foreach ($pathA AS $key => $dir) {
if ($dir == '..') {
if (end($result) == '..') {
$result[] = '..';
} elseif (!array_pop($result)) {
$result[] = '..';
}
} elseif ($dir && $dir != '.') {
$result[] = $dir;
}
}
if (!end($pathA))
$result[] = '';
return implode('/', $result);
}

Hope this helps.

charlener’s picture

Thanks a bunch! I've been banging my head about this one - and magical fix!

(I'm using civicspace, btw)

dnagirl’s picture

Hi,

I have a similar problem. Drupal copies files to /tmp directory, but then instead of moving the files to /newfiles on confirmed upload, it puts them in the root directory of my Drupal installation. However, the path to the file is /newfiles/filename as it should be.

Unfortunately my provider has also switched to PHP 5 and I cannot change the permissions of the directories outside of my public_html directory.

I put outputs of $dest inside of function file_copy. It appears that the tmp directory arrives at this function with $dest intact. But when I submit the post, the $dest variable is set to the filename with no path info. Where is that happening?

Much thanks for any help.

Cheers,
Jennifer

phildu’s picture

same problem for me when i upload image whith acidfree ?

krichlin’s picture

I also have this problem with acidfree. What gives?

michellex’s picture

hauk’s picture

In my case it was a mime-type problem when I was trying to upload a png image. That is, the drupal log says this:

"mime_content_type(/tmp/phpqJU4Vp) [function.mime-content-type]: failed to open stream: No such file or directory in /var/www/html/drupal-4.6.5/includes/file.inc on line 149."

followed by this

"For /tmp/phpzgkE48 the system thinks its MIME type is text/plain while the user has given image/png for MIME type"

/etc/mime.types has image/png -- who knows where mime_content_type() looks up the mime-type? ANyway solved this by uploading a jpeg file instead which worked okay.

kikkum’s picture

I'm having this problem too (or perhaps a variation on it). After trying to upload an image I get:

File copy failed: source file does not exist.

A log message is created saying:

For /tmp/php4TttII the system thinks its MIME type is while the user has given image/jpeg for MIME type

Not even a text/plain for me. Perhaps the problem here is that the files in /tmp aren't even really called /tmp/phpblabla but /tmp/phpblabla.txt.

Any ideas on how to fix this? Uploading a jpeg doesn't work for me either.

slaz3nger’s picture

i have this problem... with temporary files.. i want to copy the fla7.tmp( an FLV file that i got from youtube, i want to copy it) file but when i copy it, a error pop-up signs appears "can't copy fla"numer": it is being use by person or program, close any programs that might be using the file and try again"

What can i do to copy it? i already close processes in the task manager and still i cant copy it.

truly yours,
Mj Jabs
Masters in DOTA
Master in starcraft
Master in Counquer