[SOLVED] Spaces getting inserted before & after filename

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

[SOLVED] Spaces getting inserted before & after filename

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

' " . $_FILES['StaffPhoto']['name'] . " '
Notice the spaces?
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post 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:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

No problem :wink:
Post Reply