PHP:向字符串添加空格

时间:2011-08-19 12:16:04

标签: php

这个脚本自昨天开始工作以来没有改变,我用它将内容上传到我的服务器,现在它给了我错误。

剧本:

<script>
$(document).ready(function(){
$.ajax({
  type: 'GET',
  url: '../units_and_evidence/"',
  data: 'cache=yes'
});
});
</script>
<?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');
}
?>

错误:

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

正如您所看到的那样,它会在单词报告周围添加空格。报告来自$projectString,不仅原本没有空格我还将它们从中删除以保证安全。

1 个答案:

答案 0 :(得分:1)

也许他们是标签而不是空格。改为使用修剪。 http://php.net/manual/en/function.trim.php,老实说这就是我所能说的,因为我没有看到任何其他有用的代码。