Jump to content

[SOLVED] Uploader and using mkdir()


jkewlo

Recommended Posts

Hey me again :(

 

ok so I am working on this uploader to upload images to a database and a directory the directory will be named as the user username which it all works but im getting this little error

 

Warning: mkdir() [function.mkdir]: File exists in /uploadimage.php on line 7

 

The Directory is being created but what I cant figure out is a if statement or w/e to check if the directory is there and if it is upload the image and upload the path etc.. to the database if the Directory is not there create it and then upload the image path etc.. to the database. if anyone can figure something out please help me lol

 

<?php
session_start();
include("data/connect.php");
include("data/function.php");

$uploadDir = "user/". $_SESSION['myusername'] ."/";
mkdir("". $uploadDir ."/".$_SESSION["username"]."/", 0777);

if(isset($_POST['upload']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$filePath = $uploadDir . $fileName;

$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
$msg = "<span class='confirmationerror'><img src='img/x.gif'>Image was not uploaded!</span>";
exit;
}


if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$query = "UPDATE users SET name='". $fileName ."', size='". $fileSize ."', type='". $fileType ."', path='". $filePath ."' WHERE username='". $_SESSION['myusername'] ."'";

mysql_query($query) or die('Error, query failed : ' . mysql_error());


$msg = "<span class='confirmationaccept'><img src='img/check.gif'>Image Uploaded Successful!</span>";
$_SESSION['message'] = $msg;

}
?>

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/154272-solved-uploader-and-using-mkdir/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.