I.
First sorry for my terrible english!!
I've done a script to upload an image file to a directory. When I specified the path of the directory, the script works well, but I need the script to upload to diferent directories. I've tried to pass the directory path in the URL to the script but didn't work, then I've tried to pass the directory path throw a form... and didn't work either. My actual code is like this:
<?
$img_dir= $_POST['img_dir'];
$path_img_dir = $HTTP_SERVER_VARS['DOCUMENT_ROOT'].$_POST['img_dir'];
if($submit){ // se vem o submit
// se nao foi seleccionado nenhum ficheiro
if($image_name == ""){
$log="<font color=red>Não foi seleccionado nenhum ficheiro !!</font>";
}
// se já existe ficheiro com o mesmo nome
elseif(file_exists($path_img_dir."/".$image_name)){
$log="<font color=red>O ficheiro $image_name já existe !!</font>";
}
else{
$img_arr = explode(".",$image_name);
$type = end($img_arr);
if($type!="gif" and $type!="jpg" and $type!="png" and $type!="bmp" and $type!="jpeg" and $type!="jpe")
{
$log="<font color=red>Esse tipo de ficheiro não é permitido</font>";
}
else{
@copy($image,$path_img_dir."/".$image_name) or $log = "<font color=red>Não foi possivel fazer upload</font>";
if(file_exists($path_img_dir."/".$image_name)) {
$log = "<div class=uploaded>O ficheiro <a class=uploaded href=\"javascript:insertimage('[image=$image_name align=left]')\">$image_name</a> foi carregado.</div>";
}//if file exist
}// else
}// else
} //if($submit)
// form for uploading
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION=<?echo $PHP_SELF?>>
<input type=hidden value=<?echo $_POST['img_dir']?>>
<INPUT TYPE="file" NAME="image" SIZE="23"> <input type=submit name=submit value=Upload>
The $img_dir is send from another form to the script.
The script works well when I define the $path_img_dir manually, but I really need to upload files to several directories.
I hope someone can help me and thanks.