<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: A Simple File Upload Script using PHP</title>
	<atom:link href="http://rauru.com/2008/05/a-simple-file-upload-script-using-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://rauru.com/2008/05/a-simple-file-upload-script-using-php/</link>
	<description>Rauru.com is an Internet-related blog. Here I share anything I find unusual, weird, funny and/or interesting like: sites, new technologies, web development tips, css, design tricks, web advertisement, SEO, etc.</description>
	<pubDate>Sun, 06 Jul 2008 02:17:46 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Ikki</title>
		<link>http://rauru.com/2008/05/a-simple-file-upload-script-using-php/#comment-246</link>
		<dc:creator>Ikki</dc:creator>
		<pubDate>Sat, 05 Jul 2008 16:45:23 +0000</pubDate>
		<guid isPermaLink="false">http://rauru.com/?p=41#comment-246</guid>
		<description>@Karen: Strange. I didn't find any further errors on your script. Try adding this line to your upload.php:

error_reporting(E_ALL);

This function will tell PHP to display any errors it might encounter while executing this script. Please copy the error message and post it here :)</description>
		<content:encoded><![CDATA[<p>@Karen: Strange. I didn&#8217;t find any further errors on your script. Try adding this line to your upload.php:</p>
<p>error_reporting(E_ALL);</p>
<p>This function will tell PHP to display any errors it might encounter while executing this script. Please copy the error message and post it here <img src='http://rauru.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karen</title>
		<link>http://rauru.com/2008/05/a-simple-file-upload-script-using-php/#comment-245</link>
		<dc:creator>Karen</dc:creator>
		<pubDate>Sat, 05 Jul 2008 15:39:05 +0000</pubDate>
		<guid isPermaLink="false">http://rauru.com/?p=41#comment-245</guid>
		<description>Corrected the line, and..... it still gives me a blank page. This one is weird!</description>
		<content:encoded><![CDATA[<p>Corrected the line, and&#8230;.. it still gives me a blank page. This one is weird!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ikki</title>
		<link>http://rauru.com/2008/05/a-simple-file-upload-script-using-php/#comment-244</link>
		<dc:creator>Ikki</dc:creator>
		<pubDate>Fri, 04 Jul 2008 15:25:49 +0000</pubDate>
		<guid isPermaLink="false">http://rauru.com/?p=41#comment-244</guid>
		<description>@Karen: I think I found your problem. See this line in your script:

$blacklist = array(“.php”, “.phtml”, “.php3?, “.php4?, “.php5?, “.exe”, “.js”,“.html”, “.htm”, “.inc”);

You're missing some closing double-quotes in your blacklist array. It should be like this:

$blacklist = array(“.php”, “.phtml”, “.php3?”, “.php4?”, “.php5?”, “.exe”, “.js”,“.html”, “.htm”, “.inc”);

It should work now. You were getting a blank page because of a PHP error. You should enable PHP to display errors in your scripts in order to let you know when something goes wrong (but use it only on testing enviroments, never on production enviroments!).

Let me know if it worked, ok?</description>
		<content:encoded><![CDATA[<p>@Karen: I think I found your problem. See this line in your script:</p>
<p>$blacklist = array(“.php”, “.phtml”, “.php3?, “.php4?, “.php5?, “.exe”, “.js”,“.html”, “.htm”, “.inc”);</p>
<p>You&#8217;re missing some closing double-quotes in your blacklist array. It should be like this:</p>
<p>$blacklist = array(“.php”, “.phtml”, “.php3?”, “.php4?”, “.php5?”, “.exe”, “.js”,“.html”, “.htm”, “.inc”);</p>
<p>It should work now. You were getting a blank page because of a PHP error. You should enable PHP to display errors in your scripts in order to let you know when something goes wrong (but use it only on testing enviroments, never on production enviroments!).</p>
<p>Let me know if it worked, ok?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karen</title>
		<link>http://rauru.com/2008/05/a-simple-file-upload-script-using-php/#comment-243</link>
		<dc:creator>Karen</dc:creator>
		<pubDate>Fri, 04 Jul 2008 14:47:46 +0000</pubDate>
		<guid isPermaLink="false">http://rauru.com/?p=41#comment-243</guid>
		<description>Upload.php and form.html and the 'uploads' folder are all in orielchambers folder on public.html.</description>
		<content:encoded><![CDATA[<p>Upload.php and form.html and the &#8216;uploads&#8217; folder are all in orielchambers folder on public.html.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karen</title>
		<link>http://rauru.com/2008/05/a-simple-file-upload-script-using-php/#comment-242</link>
		<dc:creator>Karen</dc:creator>
		<pubDate>Fri, 04 Jul 2008 14:44:39 +0000</pubDate>
		<guid isPermaLink="false">http://rauru.com/?p=41#comment-242</guid>
		<description>No sorry it doesnt work.
Here's my script:-



&#60;?php
// Upload directory: remember to give it write permission!
$uploaddir = “upload/”;
// what file types do you want to disallow?
$blacklist = array(“.php”, “.phtml”, “.php3?, “.php4?, “.php5?, “.exe”, “.js”,“.html”, “.htm”, “.inc”);
 // allowed filetypes       
$allowed_filetypes = array(‘.jpg’,‘.gif’,‘.bmp’,‘.png’);
 
if (!is_dir($uploaddir)) {
    die (“Upload directory does not exists.”);
}
if (!is_writable($uploaddir)) {
    die (“Upload directory is not writable.”);
}
 
if ($_POST['submit']) {
 
    if (isset($_FILES['file'])) {
        if ($_FILES['file']['error'] != 0) {
            switch ($_FILES['file']['error']) {
                case 1:
                    print ‘The file is too big.’; // php installation max file size error
                    exit;
                    break;
                case 2:
                    print ‘The file is too big.’; // form max file size error - DEPRECATED
                    exit;
                    break;
                case 3:
                    print ‘Only part of the file was uploaded’.;
                    exit;
                    break;
                case 4:
                    print ‘No file was uploaded.’;
                    exit;
                    break;
                case 6:
                    print “Missing a temporary folder.”;
                    exit;
                    break;
                case 7:
                    print “Failed to write file to disk”;
                    exit;
                    break;
                case 8:
                    print “File upload stopped by extension”;
                    exit;
                    break;
            }
        } else {
            foreach ($blacklist as $item) {
                if (preg_match(“/$item\$/i”, $_FILES['file']['name'])) {
                    echo “Invalid filetype !”;
                    unset($_FILES['file']['tmp_name']);
                    exit;
                }
            }
            // Get the extension from the filename.
            $ext = substr($_FILES['file']['name'], strpos($_FILES['file']['name'],‘.’), strlen($_FILES['file']['name'])-1);
 // Check if the filetype is allowed, if not DIE and inform the user.
 if(!in_array($ext,$allowed_filetypes)){
 die(‘The file you attempted to upload is not allowed.’);
 }
 if (!file_exists($uploaddir . $_FILES["file"]["name"])) {
 // Proceed with file upload
 if (is_uploaded_file($_FILES['file']['tmp_name'])) {
 //File was uploaded to the temp dir, continue upload process
 if (move_uploaded_file($_FILES['file']['tmp_name'], $uploaddir . $_FILES['file']['name'])) {
 // uploaded file was moved and renamed succesfuly. Display a message.
 echo “Upload successful!”;
 } else {
 echo “Error while uploading the file, Please contact the webmaster.”;
 unset($_FILES['file']['tmp_name']);
 }
 } else {
 //File was NOT uploaded to the temp dir
 switch ($_FILES['file']['error']) {
 case 1:
 print ‘The file is too big.’; // php installation max file size error
 break;
 case 2:
 print ‘The file is too big.’; // form max file size error
 break;
 case 3:
 print ‘Only part of the file was uploaded’;
 break;
 case 4:
 print ‘No file was uploaded’;
 break;
 case 6:
 print “Missing a temporary folder.”;
 break;
 case 7:
 print “Failed to write file to disk”;
 break;
 case 8:
 print “File upload stopped by extension”;
 break;
 }
 }
 } else { // There’s a file with the same name
 echo “Filename already exists, Please rename the file and retry.”;
 unset($_FILES['file']['tmp_name']);
 }
        }
    } else { // user did not select a file to upload
        echo “Please select a file to upload.”;
    }
} else { // upload button was not pressed
    header(“Location: form.html”);
}
?&#62;
</description>
		<content:encoded><![CDATA[<p>No sorry it doesnt work.<br />
Here&#8217;s my script:-</p>
<p>&lt;?php<br />
// Upload directory: remember to give it write permission!<br />
$uploaddir = “upload/”;<br />
// what file types do you want to disallow?<br />
$blacklist = array(“.php”, “.phtml”, “.php3?, “.php4?, “.php5?, “.exe”, “.js”,“.html”, “.htm”, “.inc”);<br />
 // allowed filetypes       <br />
$allowed_filetypes = array(‘.jpg’,‘.gif’,‘.bmp’,‘.png’);<br />
 <br />
if (!is_dir($uploaddir)) {<br />
    die (“Upload directory does not exists.”);<br />
}<br />
if (!is_writable($uploaddir)) {<br />
    die (“Upload directory is not writable.”);<br />
}<br />
 <br />
if ($_POST['submit']) {<br />
 <br />
    if (isset($_FILES['file'])) {<br />
        if ($_FILES['file']['error'] != 0) {<br />
            switch ($_FILES['file']['error']) {<br />
                case 1:<br />
                    print ‘The file is too big.’; // php installation max file size error<br />
                    exit;<br />
                    break;<br />
                case 2:<br />
                    print ‘The file is too big.’; // form max file size error - DEPRECATED<br />
                    exit;<br />
                    break;<br />
                case 3:<br />
                    print ‘Only part of the file was uploaded’.;<br />
                    exit;<br />
                    break;<br />
                case 4:<br />
                    print ‘No file was uploaded.’;<br />
                    exit;<br />
                    break;<br />
                case 6:<br />
                    print “Missing a temporary folder.”;<br />
                    exit;<br />
                    break;<br />
                case 7:<br />
                    print “Failed to write file to disk”;<br />
                    exit;<br />
                    break;<br />
                case 8:<br />
                    print “File upload stopped by extension”;<br />
                    exit;<br />
                    break;<br />
            }<br />
        } else {<br />
            foreach ($blacklist as $item) {<br />
                if (preg_match(“/$item\$/i”, $_FILES['file']['name'])) {<br />
                    echo “Invalid filetype !”;<br />
                    unset($_FILES['file']['tmp_name']);<br />
                    exit;<br />
                }<br />
            }<br />
            // Get the extension from the filename.<br />
            $ext = substr($_FILES['file']['name'], strpos($_FILES['file']['name'],‘.’), strlen($_FILES['file']['name'])-1);<br />
 // Check if the filetype is allowed, if not DIE and inform the user.<br />
 if(!in_array($ext,$allowed_filetypes)){<br />
 die(‘The file you attempted to upload is not allowed.’);<br />
 }<br />
 if (!file_exists($uploaddir . $_FILES["file"]["name"])) {<br />
 // Proceed with file upload<br />
 if (is_uploaded_file($_FILES['file']['tmp_name'])) {<br />
 //File was uploaded to the temp dir, continue upload process<br />
 if (move_uploaded_file($_FILES['file']['tmp_name'], $uploaddir . $_FILES['file']['name'])) {<br />
 // uploaded file was moved and renamed succesfuly. Display a message.<br />
 echo “Upload successful!”;<br />
 } else {<br />
 echo “Error while uploading the file, Please contact the webmaster.”;<br />
 unset($_FILES['file']['tmp_name']);<br />
 }<br />
 } else {<br />
 //File was NOT uploaded to the temp dir<br />
 switch ($_FILES['file']['error']) {<br />
 case 1:<br />
 print ‘The file is too big.’; // php installation max file size error<br />
 break;<br />
 case 2:<br />
 print ‘The file is too big.’; // form max file size error<br />
 break;<br />
 case 3:<br />
 print ‘Only part of the file was uploaded’;<br />
 break;<br />
 case 4:<br />
 print ‘No file was uploaded’;<br />
 break;<br />
 case 6:<br />
 print “Missing a temporary folder.”;<br />
 break;<br />
 case 7:<br />
 print “Failed to write file to disk”;<br />
 break;<br />
 case 8:<br />
 print “File upload stopped by extension”;<br />
 break;<br />
 }<br />
 }<br />
 } else { // There’s a file with the same name<br />
 echo “Filename already exists, Please rename the file and retry.”;<br />
 unset($_FILES['file']['tmp_name']);<br />
 }<br />
        }<br />
    } else { // user did not select a file to upload<br />
        echo “Please select a file to upload.”;<br />
    }<br />
} else { // upload button was not pressed<br />
    header(“Location: form.html”);<br />
}<br />
?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ikki</title>
		<link>http://rauru.com/2008/05/a-simple-file-upload-script-using-php/#comment-241</link>
		<dc:creator>Ikki</dc:creator>
		<pubDate>Fri, 04 Jul 2008 14:13:04 +0000</pubDate>
		<guid isPermaLink="false">http://rauru.com/?p=41#comment-241</guid>
		<description>@Karen: I think you're setting the wrong path. Try this: put both scripts (the form and the uploaded script) in the folder "orielchambers" and set your &lt;strong&gt;$uploaddir&lt;/strong&gt; variable to &lt;strong&gt;"upload/"&lt;/strong&gt;.

If it doesn't work please let me know. I may give you a hand with your script if you allow me to do so.</description>
		<content:encoded><![CDATA[<p>@Karen: I think you&#8217;re setting the wrong path. Try this: put both scripts (the form and the uploaded script) in the folder &#8220;orielchambers&#8221; and set your <strong>$uploaddir</strong> variable to <strong>&#8220;upload/&#8221;</strong>.</p>
<p>If it doesn&#8217;t work please let me know. I may give you a hand with your script if you allow me to do so.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karen</title>
		<link>http://rauru.com/2008/05/a-simple-file-upload-script-using-php/#comment-240</link>
		<dc:creator>Karen</dc:creator>
		<pubDate>Fri, 04 Jul 2008 14:00:12 +0000</pubDate>
		<guid isPermaLink="false">http://rauru.com/?p=41#comment-240</guid>
		<description>Gave 'upload' folder writing permissions 0774.  Changed the path to 'public_html/orielchambers/upload' (the path on my server). The browser sends my page to upload.php with blank page still.</description>
		<content:encoded><![CDATA[<p>Gave &#8216;upload&#8217; folder writing permissions 0774.  Changed the path to &#8216;public_html/orielchambers/upload&#8217; (the path on my server). The browser sends my page to upload.php with blank page still.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ikki</title>
		<link>http://rauru.com/2008/05/a-simple-file-upload-script-using-php/#comment-239</link>
		<dc:creator>Ikki</dc:creator>
		<pubDate>Thu, 03 Jul 2008 15:03:28 +0000</pubDate>
		<guid isPermaLink="false">http://rauru.com/?p=41#comment-239</guid>
		<description>@Karen: You need to create a "upload" folder on your server and give it writing permissions before using this script. Remember to change the path to its location in line 3!

Give it a try and let me know if it worked, ok? ;)</description>
		<content:encoded><![CDATA[<p>@Karen: You need to create a &#8220;upload&#8221; folder on your server and give it writing permissions before using this script. Remember to change the path to its location in line 3!</p>
<p>Give it a try and let me know if it worked, ok? <img src='http://rauru.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karen</title>
		<link>http://rauru.com/2008/05/a-simple-file-upload-script-using-php/#comment-238</link>
		<dc:creator>Karen</dc:creator>
		<pubDate>Thu, 03 Jul 2008 14:29:43 +0000</pubDate>
		<guid isPermaLink="false">http://rauru.com/?p=41#comment-238</guid>
		<description>
 Do just need to upload the uploads folder, form.php and upload.php on to my site? Because in my browser when i click submit it has just a blank page... What did i do wrong?
</description>
		<content:encoded><![CDATA[<p> Do just need to upload the uploads folder, form.php and upload.php on to my site? Because in my browser when i click submit it has just a blank page&#8230; What did i do wrong?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ikki</title>
		<link>http://rauru.com/2008/05/a-simple-file-upload-script-using-php/#comment-179</link>
		<dc:creator>Ikki</dc:creator>
		<pubDate>Mon, 19 May 2008 15:35:40 +0000</pubDate>
		<guid isPermaLink="false">http://rauru.com/?p=41#comment-179</guid>
		<description>@jose: De nada ;)</description>
		<content:encoded><![CDATA[<p>@jose: De nada <img src='http://rauru.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
</channel>
</rss>
