7 Replies - 676 Views - Last Post: 24 February 2013 - 01:32 PM Rate Topic: -----

#1 hamza123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-February 13

Add a hyphen to the uploaded files

Posted 24 February 2013 - 03:29 AM

Hi Everyone,

I am very to this forum and I hope to find my answer to the question I have. I have a php file which is responsible to upload files to my server after a form is submitted. At the moment when someone upload a file with a name that has space when an email is sent to me the link to the file is sent broken! Therefore when I click on the link to view the file and download it it gives me a 404 error.

Can anyone check the code below and tell me what needs to be added to have any files uploaded to have the hyphen added to them as well as the link sent to me has the correct name (with hyphens) so when downloading it works fine?

<?php
include("class.phpmailer.php");

$mail = new PHPMailer();

$EmailFrom = "info@fireflylocums.com"; //info@fireflylocums.com
$EmailTo   = "uk.hamza@gmail.com"; // jeannine@fireflylocums.com
$Subject   = "A message from Firefly Locums Website";
$Title	   = Trim(stripslashes($_POST['Title']));
$Firstname = Trim(stripslashes($_POST['Firstname'])); 
$Surname   = Trim(stripslashes($_POST['Surname'])); 
$Address   = Trim(stripslashes($_POST['Address']));
$Postcode  = Trim(stripslashes($_POST['Postcode']));
$Email     = Trim(stripslashes($_POST['Email'])); 
$Daytime   = Trim(stripslashes($_POST['Daytime']));
$Evening   = Trim(stripslashes($_POST['Evening']));
$Mobile    = Trim(stripslashes($_POST['Mobile']));
$Current   = Trim(stripslashes($_POST['Current']));
$Sought    = Trim(stripslashes($_POST['Sought']));
$Additional= Trim(stripslashes($_POST['Additional']));


// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Title: ";
$Body .= $Title;
$Body .= "\n";
$Body .= "Firstname: ";
$Body .= $Firstname;
$Body .= "\n";
$Body .= "Surname: ";
$Body .= $Surname;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "Postcode: ";
$Body .= $Postcode;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Daytime: ";
$Body .= $Daytime;
$Body .= "\n";
$Body .= "Evening: ";
$Body .= $Evening;
$Body .= "\n";
$Body .= "Mobile: ";
$Body .= $Mobile;
$Body .= "\n";
$Body .= "Current: ";
$Body .= $Current;
$Body .= "\n";
$Body .= "Sought: ";
$Body .= $Sought;
$Body .= "\n";
$Body .= "Additional: ";
$Body .= $Additional;
$Body .= "\n";


$mail->Host    = "localhost"; // SMTP server 
$mail->From    = $EmailFrom;
$mail->Subject = "A message from Firefly Locums Website";


$mail->AddAddress($EmailTo, "");

if (is_uploaded_file($_FILES['uploadedfile']['tmp_name']))//
{
  move_uploaded_file ( $_FILES['uploadedfile']['tmp_name'] , "files/".$_FILES['uploadedfile']['name'] );
  chmod("files/". $_FILES['uploadedfile']['name'] , 0777); 
 // $mail->AddAttachment  ("files/".$_FILES['uploadedfile']['name']);
  $mail->Body    = $Body . " http://www.fireflylocums.co.uk/files/" . $_FILES['uploadedfile']['name'];
}
else
$mail->Body    = $Body;

if(!$mail->Send()) 
{
  print "Mailer Error: " . $mail->ErrorInfo;
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
} 
else
{
  if (is_uploaded_file($_FILES['uploadedfile']['tmp_name']))
  {
   // unlink("files/".$_FILES['uploadedfile']['name']);
  }

  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}

?>     



The link to the site

http://fireflylocums...register_cv.php

Thank you in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Add a hyphen to the uploaded files

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3615
  • View blog
  • Posts: 12,439
  • Joined: 12-December 12

Re: Add a hyphen to the uploaded files

Posted 24 February 2013 - 03:52 AM

Encode the spaces (and other characters) within the link:

$mail->Body = $Body . " http://www.fireflylocums.co.uk/files/" . 
    urlencode($_FILES['uploadedfile']['name']);

the docs
Was This Post Helpful? 0
  • +
  • -

#3 hamza123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-February 13

Re: Add a hyphen to the uploaded files

Posted 24 February 2013 - 05:15 AM

Thank you Andrew for your time. I am a bit not too sure what I shall be doing,

Could you kindly state what code exactly needs to be added? I have added the line you have posted and didn't work for me!
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3615
  • View blog
  • Posts: 12,439
  • Joined: 12-December 12

Re: Add a hyphen to the uploaded files

Posted 24 February 2013 - 05:36 AM

Are you saying then the link in the email does not download the file when clicked?

Check that file is saved in the correct location and with the correct filename by looking for it in your /files folder. Then check that the link in your email points to the same file and location; if you have added urlencode() as I suggested then spaces in the filename and path will be replaced with %20.
Was This Post Helpful? 0
  • +
  • -

#5 Mmsuccess  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-February 13

Re: Add a hyphen to the uploaded files

Posted 24 February 2013 - 07:33 AM

Hi Andrew

Thanks for the reply. I have added the code and it stayed the same. I receive a broken link for example www.domain.com/files/cv test.dox the link direct you to the whole path excluding test.docx because on the email it shows broken!

It doesn't add the %20
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3615
  • View blog
  • Posts: 12,439
  • Joined: 12-December 12

Re: Add a hyphen to the uploaded files

Posted 24 February 2013 - 07:41 AM

Try rawurlencode. Otherwise, post the file name as path (where it is stored on the server) and the link as it appears in the email.
Was This Post Helpful? 0
  • +
  • -

#7 hamza123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-February 13

Re: Add a hyphen to the uploaded files

Posted 24 February 2013 - 01:31 PM

Andrew,

Thank you very much Andrew, that seems to do the trick, Actually the first post you made worked it was just me not paying attention where I should have added the urlencode!

Thanks again
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3615
  • View blog
  • Posts: 12,439
  • Joined: 12-December 12

Re: Add a hyphen to the uploaded files

Posted 24 February 2013 - 01:32 PM

View Posthamza123, on 24 February 2013 - 01:31 PM, said:

Andrew,

Thank you very much Andrew, that seems to do the trick, Actually the first post you made worked it was just me not paying attention where I should have added the urlencode!

Thanks again

You are welcome. Andy.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1