<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Completely &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/completely/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>PHP Functions: realpath()</title>
		<link>/2010/05/22/php-functions-realpath/</link>
		<comments>/2010/05/22/php-functions-realpath/#respond</comments>
		<pubDate>Sat, 22 May 2010 07:30:55 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Completely]]></category>
		<category><![CDATA[Computer file]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Inter-process communication]]></category>
		<category><![CDATA[Localhost]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Software engineering]]></category>

		<guid isPermaLink="false">/?p=1530</guid>
		<description><![CDATA[Watch Out &#8211; Hard Code Perhaps every developer knows that hard coded paths are no good! The code&#8217;s good to be flexible and extensible, but what the way to achieve that? In a typically developed application you&#8217;re completely sure the way the folders are nested will be permanent and no change will occur, and that&#8217;s &#8230; <a href="/2010/05/22/php-functions-realpath/" class="more-link">Continue reading <span class="screen-reader-text">PHP Functions: realpath()</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/01/18/download-images-with-php/" rel="bookmark" title="Download Images with PHP">Download Images with PHP </a></li>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
<li><a href="/2010/09/17/5-php-string-functions-you-need-to-know/" rel="bookmark" title="5 PHP String Functions You Need to Know">5 PHP String Functions You Need to Know </a></li>
<li><a href="/2011/07/29/php-strings-how-to-get-the-extension-of-a-file/" rel="bookmark" title="PHP Strings: How to Get the Extension of a File">PHP Strings: How to Get the Extension of a File </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Watch Out &#8211; Hard Code</h2>
<p>Perhaps every developer knows that hard coded paths are no good! The code&#8217;s good to be flexible and extensible, but what the way to achieve that? In a typically developed application you&#8217;re completely sure the way the folders are nested will be permanent and no change will occur, and that&#8217;s maybe true, but however don&#8217;t be completely sure.</p>
<h2>An Example</h2>
<p>Let&#8217;s take a typical example. You&#8217;ve to access a uploaded file with PHP. By default the files are uploaded in the /tmp folder with PHP given name. That&#8217;s why immediately after the upload (the form submit) you&#8217;ve to process the _POST and the _FILES arrays and perhaps move the uploaded file somewhere else.</p>
<p>However you&#8217;d like to access this file wherever the application is &#8211; on the production servers or on the development server or even on the localhost!</p>
<p>I ran into that kind of problem/task. The thing I&#8217;d like to achieve was a bit different. I constructed the path with the <a title="php: dirname()" href="http://php.net/manual/en/function.dirname.php" target="_blank"><strong>dirname()</strong></a> function, but there were still &#8216;/../../&#8217; chunks in it. So the solution is the <a title="php: realname()" href="http://www.php.net/manual/en/function.realpath.php" target="_blank"><strong>realpath()</strong></a> function that removes those chunks and converts the path into one &#8220;calculated&#8221; real path to the file.</p>
<p>Let me show you an example:</p>
<pre lang="php">
// get the uploaded file path
$scriptPath = dirname(__FILE__);

// get the realpath to avoid the /../ part of the path
// with dirname they remain in the path
$uploadFolderPath = realpath($scriptPath . '/../../folder_name/');
</pre>
<p>If you were using dirname() you&#8217;d get something like that:</p>
<pre>/folder1/folder2/folder3/../../folder2/file.txt</pre>
<p>Now with realpath() the result is:</p>
<pre>/folder1/folder2/file.txt</pre>
<p>That&#8217;s more clear and even both are working correctly I&#8217;d prefer the second one!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/01/18/download-images-with-php/" rel="bookmark" title="Download Images with PHP">Download Images with PHP </a></li>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
<li><a href="/2010/09/17/5-php-string-functions-you-need-to-know/" rel="bookmark" title="5 PHP String Functions You Need to Know">5 PHP String Functions You Need to Know </a></li>
<li><a href="/2011/07/29/php-strings-how-to-get-the-extension-of-a-file/" rel="bookmark" title="PHP Strings: How to Get the Extension of a File">PHP Strings: How to Get the Extension of a File </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/05/22/php-functions-realpath/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
