Move File from One Folder to the other using PHP
FILE UPLOAD SCRIPT
<?php
// Check to be sure that the only request we can process is POST REQUEST
if(isset($_SERVER["REQUEST_METHOD"]) && strip_tags($_SERVER["REQUEST_METHOD"]) == strip_tags("POST"))
{
// Be default, files are uploaded to folder one
if(isset($_POST['submit']))
{
// Variables declaration
$filename = $_FILES['file']['name'];
$filesize = $_FILES['file']['size'];
$filetemp = $_FILES['file']['tmp_name'];
if($filesize < 1000000) // Maximum allowed file size is 1MB
{
$file = explode(".", $filename);
$file_ext = end($file);
$ext = array("png", "gif", "jpg", "jpeg"); // Allowed file types
// If the file trying to upload is in the list of allowed file types, proceed to upload
if(in_array($file_ext, $ext))
{
$location = "folder1/".$filename;
if(move_uploaded_file($filetemp, $location))
{
echo "<script>alert('Great, the file was uploaded successfully.')</script>";
echo "<script>window.location = 'index.php'</script>";
}
}
else // Else to not upload if its not in the list of allowed file types
{
echo "<script>alert('Sorry, you tried to upload a wrong file type\\n Allowed file types are png, gif, jpg, jpeg')</script>";
echo "<script>window.location = 'index.php'</script>";
}
}
else
{
echo "<script>alert('Sorry, the file size you tried to upload was too large.\\nMaximum allowed file size is 1MB')</script>";
echo "<script>window.location = 'index.php'</script>";
}
}
else
{
echo "<script>alert('No proper request was made')</script>";
echo "<script>window.location = 'index.php'</script>";
}
}
else
{
// Deny access if the request brought to this page is not a POST REQUEST
die('Access Denied');
}
?>
MOVE / TRANSFER FILE BETWEEN THE FOLDERS SCRIPT
<?php
// Check to be sure that the only request we can process is POST REQUEST
if(isset($_SERVER["REQUEST_METHOD"]) && strip_tags($_SERVER["REQUEST_METHOD"]) == strip_tags("POST"))
{
if(isset($_POST['transfer']))
{
$old_file_location = trim(strip_tags($_POST['old_location'])); // This is the old file location
$new_file_location = trim(strip_tags($_POST['new_location'])); // This is the new file location
if( rename( $old_file_location, $new_file_location ) )
{
echo "<script>alert('The file has been transferred successfully to ".$new_file_location."')</script>";
echo "<script>window.location = 'index.php'</script>";
}
else
{
echo "<script>alert('".$old_file_location." could not be transferred at the moment, please try again')</script>";
echo "<script>window.location = 'index.php'</script>";
}
}
else
{
echo "<script>alert('No proper request was made')</script>";
echo "<script>window.location = 'index.php'</script>";
}
}
else
{
// Deny access if the request brought to this page is not a POST REQUEST
die('Access Denied');
}
?>
Screen Shots
Click on a photo below to scroll through the screen shots of the application!
Submit your Job or Project Today!
We can help you turn your idea into reality, take over your existing project, or extend your current development team.
Submit your idea job or project below and we will follow up with you shortly.
OUR OBJECTIVE
Our objective is to reach a place where our services will be highly regarded by businesses from various industrial domains for building their innovative busines solutions with our cutting-edge technological expertise, interactive designs and uncompromised quality.
OUR MISSION
We aspire to help businesses ranging from startups to enterprises, who reach out to us with their requirements, in achieving great lengths, expanding their reach, upscaling their products, and generate a large user-base with our outstanding and cost-effective services.