Hello,
I have a bit of a problem with uploading files to existing directories on the server.
I have a script that uploads jpegs to specific folders.. it checks first if the folder exists. If it does not it creates that folder and then uploads the jpegs in there.
Now if the folder already exists it does not upload the files. What might be the reason for this ?
The code looks something like this:
if (isset ($_POST['submit'])) {
$id = $_POST['vid'];
$ams = $_POST['ams'];
$root = $_SERVER['DOCUMENT_ROOT'];
$dirL = $root.'/_lib/photos/'.$id.'/websize/';
$dirS = $root.'/_lib/photos/'.$id.'/thumbsize/';
require("gd.php");
if(isset($_FILES['pix']['name'])){
require("upload_mult.php");
if($ams==0) $ams=1;
$n = $ams;
foreach ($_FILES['pix']['error'] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$name = $id.'0'.++$n;
if(imageResize($_FILES['pix']['tmp_name'][$key], 400, 300)) {
if(storefileM('pix', $key, $dirL, $name.'.jpg', 768000)) {
if(imageCrop($dirL.$name.'.jpg', $dirS.$name.'.jpg', 0.41)){
$sqlInsert = 'INSERT INTO photos ( photo_id , photo_name) VALUES ( "'.$id.'", "'.$name.'");';
mysql_query($sqlInsert, $db);
}
} else {$e = 2; $error = true;}
} else {$e = 1; $error = true;}
}
}
}
if($error==true){
header("Location: uploadfailed.php?error=".$e."");
} else { header("Location: uploadok.php"); }
}
$vid = $_GET['v_id'];
$dir = $_SERVER['DOCUMENT_ROOT'].'/_lib/photos/'.$vid;
if(!is_dir($dir)){
mkdir($dir);
mkdir($dir.'/websize');
mkdir($dir.'/thumbsize');
}
BTW: mkdir is creating the folders using chmod755 and all existing folders have chmod777 which I assigned manually with a script using chmod()