I have file uploading script and I have an if statement that checks if the file does not exists it will create one and upload file to it and if it exists it will upload the file to it.
<?php
ini_set('post_max_size', '40M');
ini_set('upload_max_filesize', '40M');
if (isset($_POST['do']) and $_POST['do'] == 'upload') {
$filename = $_FILES['file']['name'];
$filesize = $_FILES['file']['size'];
$tmp_name = $_FILES['file']['tmp_name'];
$file_type = $_FILES['file']['type'];
$date = "[".date("d-m-Y_H-i")."]";
$temp = explode(".", $filename);
$new_filename = $temp[0] . ""/*you can put any thing that you want before the [] in the 2 singels*/ . $date .'.' . end($temp);
$f_folder = "uploads" . DIRECTORY_SEPARATOR .$_POST['user'] . DIRECTORY_SEPARATOR . $new_filename;
$username = $_POST['user'];
//echo $username;
if (!file_exists("uploads". DIRECTORY_SEPARATOR .$_POST['user'])){
mkdir("uploads" . DIRECTORY_SEPARATOR . $_POST['user'],0777);
if (empty($filename)) {
echo "choose file please";
}else {
move_uploaded_file($tmp_name, $f_folder);
echo "file is uploaded in " . $f_folder;
}
}else if (empty($filename)) {
echo "choose file please";
}else {
move_uploaded_file($tmp_name, $f_folder);
echo "file is uploaded in " . $f_folder;
};
};
echo "<hr>";
echo "
<form method='post' enctype='multipart/form-data' >
File Path : <input type='file' name='file' />
<br>
Username : <input type='text' name='user' />
<br>
<input type='submit' name='do' value='upload' />
</form>";
?>
It works correctly but when I upload a photo, I can't open it. It gives me the following error:
windows photo viewer can't open this picture because you don't have the correct permissions to access the file location
-i have updated the code