Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.