Hi,

I have tried to use the following example to upload a file into my image directory which was located at sites/all/images.

  $validators = array(
    'file_validate_is_image' => array(),
    'file_validate_image_resolution' => array('85x85')),
    'file_validate_size' => array(30 * 1024),
  );
  if ($file = file_save_upload('picture_upload', $validators)) {
    // All that validation is taken care of... but image was saved using
    // file_save_upload() and was added to the files table as a
    // temporary file. We'll make a copy and let the garbage collector
    // delete the original upload.
    $info = image_get_info($file->filepath);
    $destination = 'files/picture.'. $info['extension'];
    file_copy($file, $destination, FILE_EXISTS_REPLACE);
  }

But i was trying to getting the error message like The selected file sites/default/files/file.jpg could not be uploaded, because the destination is not properly configured.. After dig around it, i found that the function "file_copy" returning the error. And Withing the file_code code, the fnction "file_check_path" returning FALSE.

  $dest = file_create_path($dest);

  $directory = $dest;
  $basename = file_check_path($directory);
  .....

And within the "file_check_path" code actually the function "file_check_location" malfunctioning.

....
else {
    // This file does not yet exist
    $source = realpath(dirname($source)) .'/'. basename($source);
  }
....

Withing the file_check_location function, the function "realpath" returning no string, because its checking the file existence. But during copy, the file still not copied to the destination directory. Another thing is that on the following code...

 $directory = realpath($directory);
  if ($directory && strpos($source, $directory) !== 0) {
    return 0;
  }

It strpos also could create problem for window directory.

thanks

Comments

shafiqhossain’s picture

Status: Active » Closed (fixed)

Sorry I found the problem. I was using the absolute directory as "c:/My Work2/src/...", which i had added before the file name in order to upload my own directory. The problem was upper case and lower case of the directory name. I changed the "c:/" -> "C:/", Now its working.

thanks