I had a discussion a few weeks ago regarding getting Swift Mailer to work, and thought I had it all resolved but then got sidetracked.

I’m back on it now and realizing that I’m still running into an issue that I haven’t found a solution to.

I have a form that someone fills out, and then a place where they browse to select a file to attach to the email that is sent when submitted.

I have a folder on the server for uploaded docs to be temporarily stored in called 'uploads' with permissions set to 777 to test

This is the error that is displayed
Warning: copy(uploads/2 days - sharable.png): failed to open stream: No such file or directory in /home/username/public_html/details/forms/form_earnings.php on line 90

// define the folder to upload file to
$upload_folder = 'uploads/';

// ****  Possibly use the ID_doc/etc. with random key as filename??

$max_allowed_file_size = 500; // size in KB
$allowed_extensions = array("jpg", "jpeg", "gif", "png", "pdf");

if (basename($_FILES['ID_doc']['name']) != ''){

  //Get the uploaded files information
  $name_of_uploaded_ID_doc =
$_SESSION['id_doc'] = $name_of_uploaded_ID_doc;
  //get the file extension of the file
  $type_of_uploaded_ID_doc =
      strrpos($name_of_uploaded_ID_doc, '.') + 1);

  //get the size of the file in KBs
  $size_of_uploaded_ID_doc = $_FILES["ID_doc"]["size"]/1024;
  if($size_of_uploaded_ID_doc > $max_allowed_file_size ){
    $errors .= "<br /><br />Size of ID Document should be less than $max_allowed_file_size";

  // Validate the file extension for ID document
  $allowed_ext_ID_doc = false;
  for($i=0; $i<sizeof($allowed_extensions); $i++){
    if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_ID_doc) == 0){
      $allowed_ext_ID_doc = true;

    $errors .= "<br /><br />The uploaded ID Document is a <font color='#FF0000'>".$type_of_uploaded_ID_doc."</font> file type. ".
    "<br />Only the following file types are supported: ".implode(',',$allowed_extensions);

  // copy the temp uploaded files to uploads folder for ID_doc
  $path_of_uploaded_ID_doc = $upload_folder . $name_of_uploaded_ID_doc;
  $tmp_path_ID_doc = $_FILES["ID_doc"]["tmp_name"];

$_SESSION['uploaded_path'] = $path_of_uploaded_ID_doc;
$_SESSION['id_doc_temp_path'] = $tmp_path_ID_doc;

This is 'LINE 90' - where I run into the problem - I always get the error while copying the ID Document
(actually this was working when I last worked on this and I don't know what would have changed it)

    if(!copy($tmp_path_ID_doc,$path_of_uploaded_ID_doc)){ // line 90
      $errors .= '<br /><br />error while copying the ID Document';
      $ID_uploaded = 'yes';

  $errors .= '<br /><br />You MUST Submit an ID Document';

The values of the variables are what I expect them to be

| ['id_doc'] = String(21) "2 days - sharable.png"
| ['uploaded_path'] = String(29) "uploads/2 days - sharable.png"
| ['id_doc_temp_path'] = String(14) "/tmp/phpX8YCsR"

Any suggestions as to what I should look for would be greatly appreciated


Simple Solution...

Have an uploads file on the server where it is expected instead of the wrong directory...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.