[drupal-devel] [bug] File copy failed: source file does not exist.
(image module)
dmjossel
drupal-devel at drupal.org
Wed Sep 21 08:34:46 UTC 2005
Issue status update for
http://drupal.org/node/30371
Post a follow up:
http://drupal.org/project/comments/add/30371
Project: Drupal
Version: 4.6.3
Component: file system
Category: bug reports
Priority: normal
Assigned to: Anonymous
Reported by: sstrange
Updated by: dmjossel
Status: active
I have a similar experience with the same error message, although the
ability to add new images and to upload files seems unaffected. Only
the update-image.php script is affected.
Also, PHP is not running in safe mode:
http://drupal.org/node/31816
Given that new images can be added, and all the paths are correct and
readable (as well as writeable in the case of the images and temp
folders, and PHP safe mode is off, it seems that there may be another
obscure issue.
The same server and web configuration works with Drupal 4.5's image
module, as well.
dmjossel
Previous comments:
------------------------------------------------------------------------
Sun, 04 Sep 2005 11:59:23 +0000 : sstrange
I've installed drupal version 4.6.3 and almost everything is working
except the image and upload modules.
When I try to create an image content I get the next error message:
File copy failed: source file does not exist.
Background info:
I've drupal installed on at my hosting company which has PHP in safe
mode. (4.3.11).
Drupal directory structure:
+---drupal
| +---database
| +---files (777)
| | +---images (777)
| | | +---temp (777)
| | | \---tmp (777)
| | \---pictures (777)
| +---includes
| +---misc
| +---modules
| | \---po
| +---scripts
| +---sites
| | \---default
| +---themes
| | +---bluemarine
| | +---chameleon
| | | \---marvin
| | +---engines
| | | +---phptemplate
| | | \---xtemplate
| | +---greenmarinee
| | \---pushbutton
| \---tmp
I'm able to upload files with the move_uploaded_file module with an
phpupload.php script from my hosting party.
There are no errors in the settings of the image module of drupal.
Default image path is "images".
What do I've to do to solve the image upload problem?
Regards,
Stefan
------------------------------------------------------------------------
Sun, 04 Sep 2005 18:57:45 +0000 : Bèr Kessels
AFAIK tmp is relative to your OS root.
so /tmp is not files/tmp but the actual /tmp of your OS/server. So make
sure you set the TMP relative to your files directory, or give an
absolute path. Something like /var/ww/drupal/files/tmp
------------------------------------------------------------------------
Mon, 05 Sep 2005 13:07:53 +0000 : sstrange
I changed the Temporary directory settings from "tmp" to
"/ext/s/st/stranger.nl/html/drupal/tmp" and saved the configuration.
(no errors when saving settings)
But I still get the error File copy failed: source file does not exist.
------------------------------------------------------------------------
Mon, 05 Sep 2005 14:02:46 +0000 : Bèr Kessels
hmm; Sstrange.; (sorry could not resist ;) ) Can you see what permssions
you have for the files _inside_ tmp? if tehre are any, that is. It could
be that thefiles themselves have problems with permissions once put
there
Other then that, I am afraid I cannot help you any further.
------------------------------------------------------------------------
Mon, 05 Sep 2005 18:07:19 +0000 : sstrange
I'm not sure what you mean with "files _inside_ tmp" but the permissions
on html/drupal/tmp are 777. But there are no files within in tmp
directory. But I can put files in that directory by ftp.
How do I know what the default tmp directory is from my hosting
company?
Regards,
Stefan
------------------------------------------------------------------------
Mon, 05 Sep 2005 19:32:28 +0000 : Bèr Kessels
I meant files, that were stuck in that directory. Or might have been.
But the fact there are no files at all in that dir, should help a lot
too.
Though I am lost at this moment.
------------------------------------------------------------------------
Tue, 06 Sep 2005 19:54:27 +0000 : walkah
this seems to be a general file system issue - i'm suspicious of safe
mode, but can't test further atm.
------------------------------------------------------------------------
Wed, 07 Sep 2005 09:43:43 +0000 : sstrange
Can anyone please tell me how the image module works? What are the
actions when an image is uploaded? In which directories are the
(temporary files) placed before they are placed in the right directory?
Regards,
Stefan
------------------------------------------------------------------------
Thu, 08 Sep 2005 18:55:15 +0000 : sstrange
According to the helpdesk of my hosting provider uses the file.inc (API
for handling file uploads and server file management) the file_copy
function which does not work with the safe mode restriction of my
provider.
Is not it posible to use the move_uploaded_file function instead of the
file_copy function?
If so who can help me?
Regards,
Stefan
------------------------------------------------------------------------
Sun, 18 Sep 2005 02:47:26 +0000 : cuebix
That is indeed the problem. I added a few lines of code inside of
includes/file.inc to find out what was going on:
$source = realpath($source);
var_dump($source);
exit;
if (!file_exists($source)) {
drupal_set_message(t('File copy failed: source file does not
exist.'), 'error');
return 0;
}
When uploading a file, this output:
string(14) "/tmp/phpz4d3CH"
The problem is, if you have safe_mode enabled, the conditional
statement will fail. /tmp resides outside of the paths the script is
allowed to work with, so even though the file exists, the function
file_exists() plays dumb, as it should. The solution is, as suggested,
to use move_uploaded_file instead.
I've created a workaround for it for Drupal 4.6.3
In includes/file.inc
in file_copy(...)
Line 231: if (!file_exists($source) && !is_uploaded_file($source)) {
drupal_set_message(t('File copy failed: source file does not exist.'),
'error');
return 0;
}
Line 272: if (is_uploaded_file($source)) {
if (!move_uploaded_file($source, $dest)) {
drupal_set_message(t('File copy failed.'), 'error');
return 0;
}
} else if (!@copy($source, $dest)) {
drupal_set_message(t('File copy failed.'), 'error');
return 0;
}
in file_move(...)
Line 314: if (is_uploaded_file($path_original)) {
$uploaded_file = true;
}
if (file_copy($source, $dest, $replace)) {
$path_current = is_object($source) ? $source->filepath : $source;
if ($uploaded_file || $path_original == $path_current ||
file_delete($path_original)) {
return 1;
}
drupal_set_message(t('Removing original file failed.'), 'error');
}
For some reason the regular upload module still won't work though.
------------------------------------------------------------------------
Tue, 20 Sep 2005 19:41:15 +0000 : sstrange
Attachment: http://drupal.org/files/issues/file_0.inc (17.48 KB)
I changed the file.inc according to you advise but now I'm getting the
next error message:
Parse error: parse error, unexpected $ in
/mnt/storage2/s/st/stranger.nl/html/drupal/includes/file.inc on line
559
See attached file.inc
More information about the drupal-devel
mailing list