<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
# Determines which file extensions will be allowed for upload
$allowedExtensions = array("txt","csv","htm","html","xml","zip",
"css","doc","xls","docx","xlsx","rtf","ppt","pdf","swf","flv","avi",
"wmv","mov","jpg","jpeg","gif","png","tif","psd");
foreach ($_FILES as $file) {
if ($file['tmp_name'] > '') {
if (!in_array(end(explode(".",
strtolower($file['name']))),
$allowedExtensions)) {
die($file['name'].' is an invalid file type!<br/>'.
'<a href="javascript:history.go(-1);">'.
'<< Go Back</a>');
}
}
}
$newdirectory=$_POST["imgdir"];
$imgname=$_POST["imgname"];
$zipdirectory=$_POST["extractdir"].$_POST["extractname"];
$zipflag=$_POST["zipflag"];
$imgflag=$_POST["imgflag"];
if($newdirectory!="")
$target = "<webroot1>".$newdirectory;
else
$target = "<webroot2>";
#$target = $target . basename( $_FILES['uploaded']['name']);
$basename =basename($_FILES['uploaded']['name']);
$file_name=($_FILES['uploaded']['name']);
$file_name=(strtolower($_FILES['uploaded']['name']));/* converts the file name you see for confirmation to lower case */
$file_name=preg_replace('/[^a-zA-Z0-9\.]/', '', $file_name);/* removes all unwanted characters from the file name you see for confirmation*/
$temp_name=($_FILES['uploaded']['tmp_name']);
$file_size=($_FILES['uploaded']['size']);
$file_type=($_FILES['uploaded']['type']);
$ok=1;
//This is our size condition
if ($file_size > 5000000)
{
echo "Your file is too large.<br>".$file_size."<br />";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded because of an error";
}
//If everything is ok we try to upload it
else
{
$newfile = strtolower(basename( $_FILES['uploaded']['name'])); /* converts the file name to lower case */
$newfile1 = preg_replace('/[^a-zA-Z0-9\.]/', '', $newfile); /* removes all unwanted characters */
if ($imgflag=='yes')
$target = $target.$imgname;
else
$target = $target.$newfile1;
if(move_uploaded_file($temp_name, $target))
{
chmod($target,0644);
if ($zipflag=='yes')
{
$zip = new ZipArchive;
if ($zip->open($target) === TRUE)
{
$zip->extractTo($zipdirectory);
$zip->close();
chmod($zipdirectory,0777);
$files = array();
if ($handle = opendir($zipdirectory)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..")
chmod($zipdirectory."/".$file,0777);
}
closedir($handle);
}
echo "The zip file " .$target. " has been uploaded."."<br />".
"<input type='button' id='btncontinue' value='CLICK HERE TO COMPLETE UPLOAD' />".
"<input type='hidden' name='uploadstat' id='uploadstat' value='yes' />";
}
else
{
echo "<br />"."Sorry, there was a problem uploading your zip file.".
"<input type='hidden' name='uploadstat' id='uploadstat' value='no' />";
}
}
else
{
echo "The file " .$target. " has been uploaded."."<br />"." SRC=".$temp_name."<br />".
"<input type='button' id='btncontinue' value='CLICK HERE TO COMPLETE UPLOAD' />".
"<input type='hidden' name='uploadfilename' id='uploadfilename' value='".$newfile1."' />".
"<input type='hidden' name='uploadstat' id='uploadstat' value='yes' />";
}
}
else
{
/******* THIS CODE IS HIT WHEN FILE FAILS ******/
echo "<br />"."Sorry, there was a problem uploading your file. SRC=".$temp_name."<br />"." TARGET=".$target.
"<input type='hidden' name='uploadstat' id='uploadstat' value='no' />";
}
}
connection_aborted();
?>
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE