Page 1 of 1

[SOLVED] Spaces getting inserted before & after filename

Posted: Sat May 14, 2005 11:17 am
by cdickson
I'm working on a very small database where I am uploading data and an image. For some reason a space is getting inserted immediately before and after the image filename, and I can't figure out how it's happening so that I can get rid of them.

UPLOAD CODE:

Code: Select all

if($HTTP_POST_VARS['Upload'] == "Upload"){
}
 
if($_POST['Upload'] == "Upload"){
 
$originalImageFileName = $_FILES['StaffPhoto']['name'];
$tempImageFileName = $_FILES['StaffPhoto']['tmp_name'];
 
$siteRoot = $_SERVER["DOCUMENT_ROOT"];
$uploadDir = $siteRoot . "/test2/";
$newImagePath = "/test2/staff/" . $originalImageFileName;
 
umask(0);
move_uploaded_file($tempImageFileName, $newImagePath);
system("chmod 755 $newPath");

$query = "INSERT INTO staff (
	StaffName, StaffTitle, StaffPhoto) 
	VALUES (' " . $_POST['StaffName'] . " ', ' " . $_POST['StaffTitle'] . " ', ' " . $_FILES['StaffPhoto']['name'] . " ')";

$result = mysql_query($query);
$lastInserted = mysql_insert_id();
} 
?>
DISPLAY UPLOADED INFORMATION CODE:

Code: Select all

$query  = "SELECT * FROM staff";         
  $result = mysql_query($query) or die("Error: " . mysql_error());
  $row = mysql_fetch_array ($result); // retrieve information
  while($row = mysql_fetch_array($result)){
  echo '<table width="400" border="0" cellspacing="0" cellpadding="5">
    <tr class="bodytext">
      <td align="left">' . $row['StaffName'] . '<br>
	  ' . $row['StaffTitle'] . '</td>
      <td align="center"><img src="staff/' . $row["StaffPhoto"] . '"></td>
    </tr>
  </table>';
  }
  mysql_free_result($result);
When I display the information, however, the photos don't appear. When I look at the source code that is generated, it reads as follows:

Code: Select all

&lt;img src=&quote;staff/ filename.jpg &quote;&gt;
Any help would be sincerely appreciated.

Posted: Sat May 14, 2005 11:29 am
by John Cartwright

Code: Select all

' " . $_FILES['StaffPhoto']['name'] . " '
Notice the spaces?

Posted: Sat May 14, 2005 12:18 pm
by cdickson
OMG I feel so dumb! Before posting this I tried

Code: Select all

' ". $_FILES['StaffPhoto']['name'] ." '
and

Code: Select all

' " .$_FILES['StaffPhoto']['name']. " '
but not

Code: Select all

'" . $_FILES['StaffPhoto']['name'] . "'
Thanks! :oops:

Posted: Sat May 14, 2005 12:19 pm
by John Cartwright
No problem :wink: