Hello, when some submits this form its get send to my email. If the picture or attachment has a space in it ( ex: tom file.docx) the hyperlink gets messed up.
I attach a picture of it below.
Thank you so much!

<?php
if(isset($_POST['email'])) {
     

    $email_to = "talent@itarep.com";     
     
    function died($error) {
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

	  if ($_FILES["picture"]["error"] > 0)
	    {
	    //echo "Return Code: " . $_FILES["picture"]["error"] . "<br />";
	    }
	    else
	      {
	      move_uploaded_file($_FILES["picture"]["tmp_name"],
	      "pictures/" . $_FILES["picture"]["name"]);
	      $picture_url = "http://www.itarep.com/" . "pictures/" . $_FILES["picture"]["name"];
	      }
	}
	else
	  {
	  //echo "Invalid file";
	  }

	
	 if ($_FILES["attachment"]["error"] > 0)
	    {
	    //echo "Return Code: " . $_FILES["picture"]["error"] . "<br />";
	    }
	   else
	      {
	      move_uploaded_file($_FILES["attachment"]["tmp_name"],
	      "attachments/" . $_FILES["attachment"]["name"]);
	      $attachment_url = "http://www.itarep.com/" . "attachments/" . $_FILES["attachment"]["name"];
	      }

    $name = $_POST['name'];
    $email = $_POST['email'];
    $gender = $_POST['gender'];
    $dobM = $_POST['dobM']; 
    $dobD = $_POST['dobD']; 
    $dobY = $_POST['dobY']; 
    $dobM = $_POST['dobM']; 
    $phone = $_POST['phone']; 
    $location = $_POST['location']; 
    $school = $_POST['school']; 
    $facebook = $_POST['facebook']; 
    $twitter = $_POST['twitter']; 
    $talent = $_POST['talent']; 
    $past = $_POST['past']; 
     
    $email_subject = $name . " - " . $gender . " - " . $dobY . " - " . $talent;
    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "Name: ".clean_string($name)."\n";
    $email_message .= "Email: ".clean_string($email)."\n";
    $email_message .= "Gender: ".clean_string($gender)."\n";
    $email_message .= "Date of Birth: ".clean_string($dobM)."/".clean_string($dobD)."/".clean_string($dobY)."\n";
    $email_message .= "Phone: ".clean_string($phone)."\n";
    $email_message .= "Location: ".clean_string($location)."\n";
    $email_message .= "University/High School: ".clean_string($school)."\n";
    $email_message .= "Facebook: ".clean_string($facebook)."\n";
    $email_message .= "Twitter: ".clean_string($twitter)."\n";
    $email_message .= "Talent: ".clean_string($talent)."\n";
    $email_message .= "Past work, Experiences, Expectations: ".clean_string($past)."\n";   
	$email_message .= "Picture: ".clean_string($picture_url)."\n"; 
	$email_message .= "Attachment: ".clean_string($attachment_url)."\n";   
     
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>
 

<script type="text/javascript">
window.location = "http://www.itarep.com/success.php";
</script>

<?php

?>

What spaces? could you please show me

With urlencode:

$attachment_url = "http://www.itarep.com/" . "attachments/" . urlencode($_FILES["attachment"]["name"]);
#output http://www.itarep.com/attachments/name%20file.pdf

With str_replace:

$attachment_url = "http://www.itarep.com/" . "attachments/" . str_replace(' ','_'$_FILES["attachment"]["name"]);
#output http://www.itarep.com/attachments/name_file.pdf

do the same for the images. If you replace spaces with underscore, remember also to rename the uploaded files. you can use mv() function. Bye.

I know i sound like a complete noob. But it just isn't working for me. I am really sorry for asking you this but can you just edit it and paste it on here. I am greatly appreciate it!

No problem:

<?php
if(isset($_POST['email'])) {
     

    $email_to = "talent@itarep.com";     
     
    function died($error) {
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

	  if ($_FILES["picture"]["error"] > 0)
	    {
	    //echo "Return Code: " . $_FILES["picture"]["error"] . "<br />";
	    }
	    else
	      {
	      move_uploaded_file($_FILES["picture"]["tmp_name"],
	      "pictures/" . $_FILES["picture"]["name"]);
	      $picture_url = "http://www.itarep.com/" . "pictures/" . urlencode($_FILES["picture"]["name"]);
	      }
	}
	else
	  {
	  //echo "Invalid file";
	  }

	
	 if ($_FILES["attachment"]["error"] > 0)
	    {
	    //echo "Return Code: " . $_FILES["picture"]["error"] . "<br />";
	    }
	   else
	      {
	      move_uploaded_file($_FILES["attachment"]["tmp_name"],
	      "attachments/" . $_FILES["attachment"]["name"]);
	      $attachment_url = "http://www.itarep.com/" . "attachments/" . urlencode($_FILES["attachment"]["name"]);
	      }

    $name = $_POST['name'];
    $email = $_POST['email'];
    $gender = $_POST['gender'];
    $dobM = $_POST['dobM']; 
    $dobD = $_POST['dobD']; 
    $dobY = $_POST['dobY']; 
    $dobM = $_POST['dobM']; 
    $phone = $_POST['phone']; 
    $location = $_POST['location']; 
    $school = $_POST['school']; 
    $facebook = $_POST['facebook']; 
    $twitter = $_POST['twitter']; 
    $talent = $_POST['talent']; 
    $past = $_POST['past']; 
     
    $email_subject = $name . " - " . $gender . " - " . $dobY . " - " . $talent;
    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "Name: ".clean_string($name)."\n";
    $email_message .= "Email: ".clean_string($email)."\n";
    $email_message .= "Gender: ".clean_string($gender)."\n";
    $email_message .= "Date of Birth: ".clean_string($dobM)."/".clean_string($dobD)."/".clean_string($dobY)."\n";
    $email_message .= "Phone: ".clean_string($phone)."\n";
    $email_message .= "Location: ".clean_string($location)."\n";
    $email_message .= "University/High School: ".clean_string($school)."\n";
    $email_message .= "Facebook: ".clean_string($facebook)."\n";
    $email_message .= "Twitter: ".clean_string($twitter)."\n";
    $email_message .= "Talent: ".clean_string($talent)."\n";
    $email_message .= "Past work, Experiences, Expectations: ".clean_string($past)."\n";   
	$email_message .= "Picture: ".clean_string($picture_url)."\n"; 
	$email_message .= "Attachment: ".clean_string($attachment_url)."\n";   
     
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>
 

<script type="text/javascript">
window.location = "http://www.itarep.com/success.php";
</script>

Just a note, urlencode() will replace spaces with +, if you want to use %20 character than change urlencode() to rawurlencode(). Bye :)

holy crap. I literally copy and pasted it. didn't work. then i changed urlencode to rawurlencode..didnt work. can ipay u to do this

never mind it works:) thanks

You're welcome, bye :)

Be a part of the DaniWeb community

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