PHP: adding whitespaces to string
<p>This script hasn't changed since yesterday when it was working and I used it to upload things to my server now it is giving me errors.</p>

<p>The script:</p>

<pre><code>&lt;script&gt;
$(document).ready(function(){
$.ajax({
  type: 'GET',
  url: '../units_and_evidence/"',
  data: 'cache=yes'
});
});
&lt;/script&gt;
&lt;?php
include($_SERVER['DOCUMENT_ROOT']."/dbconnect.php");
$filetype = $_POST["filetype"];
$file= $_FILES["file"]["name"];
$extension = strtoupper(strrchr($file, "."));
$filename = substr($file, 0, -strlen($extension));
$unitID = $_POST["units"];
$projectID = $_POST["project"];
$title = $_POST["title"];
$projectString = strtolower(str_replace(" ", "", $_POST["projectString"]));
$target_path = '../units_and_evidence/files/'.$projectString.'/'. basename( $_FILES['file']['name']);
$outcomes = implode(',', $_POST["outcomes"]);
if(is_uploaded_file($_FILES['source']['tmp_name'])) {
$source_path = '../units_and_evidence/files/'.$projectString.'/'.$filename.'.fla';
move_uploaded_file($_FILES['source']['tmp_name'], $source_path) or die("Couldn't upload source file");
}
if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
mysql_select_db('reithg_FILES');
if ($filetype == "PDF") {
$page = $_POST["page"];
$mode = $_POST["mode"];
mysql_query("INSERT INTO PDF (ID, UNITID, PROJECTID, OUTCOMES, TITLE, FILENAME, PAGE, MODE, FILETYPE) VALUES('NULL', '$unitID', '$projectID', '$outcomes', '$title', '$filename', '$page', '$mode', '$filetype') ") or die(mysql_error());  
}
else if ($filetype == "IMG") {
mysql_query("INSERT INTO IMG (ID, UNITID, PROJECTID, OUTCOMES, TITLE, FILENAME, EXTENSION, FILETYPE) VALUES('NULL', '$unitID', '$projectID', '$outcomes', '$title', '$filename', '$extension', '$filetype') ") or die(mysql_error());  
}
else if ($filetype == "FLASH") {         
mysql_query("INSERT INTO FLASH (ID, UNITID, PROJECTID, OUTCOMES, TITLE, FILENAME, FILETYPE) VALUES('NULL', '$unitID', '$projectID', '$outcomes', '$title', '$filename', '$filetype') ") or die(mysql_error());  
}
header('Location: upload_file.php?success=true');
} else{
header('Location: upload_file.php?success=false');
}
?&gt;
</code></pre>

<p>The error:</p>

<pre><code>Warning: move_uploaded_file(../units_and_evidence/files/ report /eHealth evaluation_Final.pdf) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/reithg/public_html/admin/process.php on line 17

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpPcxZxC' to '../units_and_evidence/files/ report /eHealth evaluation_Final.pdf' in /home/reithg/public_html/admin/process.php on line 17
</code></pre>

<p>As you can see it is adding whitespaces around the word report. report comes from <code>$projectString</code> and not only does it not have whitespaces in originally I also strip them out of it for safety.</p>
