Uploaded files

Hi, I need some help with an upload problem. Some of the files that members are uploading have spaces in the name, ex. file name.pdf. When the url is created it can't find this file because of the blank space. How do I trim this?

Here is how I access the download file:

 <?PHP if ($row_events['download1'] == NULL) {echo "";} else { echo "<img src=\"../images/pdficon.gif\" alt=\"pdf\" width=\"20\" height=\"22\" align=\"absmiddle\" /> <a href=\"../admin/upload/$row_events[download1]\" target=\"_blank\">$row_events[download1]</a>";} ?>

Thank you for your help. Have a good day.

Rob
pertrai1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

emphamyCommented:
use urlencode() .. code attached =)
 <?PHP 
if ($row_events['download1'] == NULL) {echo "";} else { echo "<img src=\"../images/pdficon.gif\" alt=\"pdf\" width=\"20\" height=\"22\" align=\"absmiddle\" /> <a href=\"../admin/upload/".urlencode($row_events[download1])."\" target=\"_blank\">$row_events[download1]</a>";} 
?>

Open in new window

0
pertrai1Author Commented:
Hey emphamy, thank you for the reply. It looks like my problem is that the file is uploading to the database but not to the directory supplied.

Could you take a look at my code snippet and tell me what I need to change to get the file uploaded to the directory as well. Thank you much.

Rob
<?
if(isset($_POST['upload']))
{
 
		$fileName = $_FILES['userfile']['name'];
		$tmpName  = $_FILES['userfile']['tmp_name'];
		$fileSize = $_FILES['userfile']['size'];
		$fileType = $_FILES['userfile']['type'];
		 
		 move_uploaded_file($_FILES['userfile']['tmp_name'],
      'upload/' . $_FILES['userfile']['name']);
      echo "Stored in: ' . 'upload/' . $_FILES['userfile']['name']";
		
		$fp = fopen($tmpName, 'r');
		$content = fread($fp, $fileSize);
		$content = addslashes($content);
		fclose($fp);
		
		if(!get_magic_quotes_gpc())
		{
			$fileName = addslashes($fileName);
		}
		
		
		
		$query = "INSERT INTO upload (name, size, type, content ) ".
		         "VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
 
		mysql_query($query) or die('Error, query failed');				
		
		echo "<br>File $fileName uploaded<br>";
}		
?>
<form action="" method="post" enctype="multipart/form-data" name="uploadform">
  <table width="500" border="0" cellpadding="1" cellspacing="1" class="box">
    <tr> 
      <td width="400"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" class="box" id="userfile" size="50">
		 </td>
      <td width="100"><input name="upload" type="submit" class="box" id="upload" value="  Upload  "></td>
    </tr>
  </table>
</form>

Open in new window

0
dr_dedoCommented:
your upload script is ok, maybe it is a folder permission problem
to overcome that blank space problem, u can replace and strange chr to _
a simple script like this can get it done

$arr= array(' ','!','*','%','\\','/');
$hay = "this is a good ! @ example # $%%";
$hay= str_replace($arr,'_',$hay);
echo $hay;

also, change line 12 to
echo "Stored in: " . 'upload/' . $_FILES['userfile']['name'];
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dttriCommented:
Greetings,

In your code. The line:
move_uploaded_file($_FILES['userfile']['tmp_name'], 'upload/' . $_FILES['userfile']['name']);

move the uploaded files from temporary directory to the correct directory. Make sure that you have a directory named 'upload' with write permission for the account execute this PHP script, and that directory has to reside in the same place as the PHP script.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.