Log in

View Full Version : rename file getting hung up



pkcidstudio
04-27-2007, 04:32 PM
I was searching and found a similar topic from a year, but didnt want to bump it.



For some reason my code is getting hung up, it isnt presenting any errors, but it isnt completeing the task either. Thanks for the help in advance.


function documentName_change()

{

//The table we are choosing to connect to

$tbl_name = "pr_mngmnt_manual";

// find out how many records there are to update

$documentName_size = count($_POST['document']);



// start a loop in order to update each record

$i = 0;

while ($i < $documentName_size) {

$query = mysql_query("SELECT DISTINCT id, document, filetype, title FROM $tbl_name");

$num = mysql_numrows($query);

$id = 0;

while ($id < $num) {

// names of the columns that hold the information prior to an update to that particular row.

$id = mysql_result($query,$id,"id");

$document = mysql_result($query,$id,"document");

$directory = mysql_result($query,$id,"filetype");

$subfolder = mysql_result($query,$id,"title");

$newDocumentName = "sys:apache2\htdocs\usa\docs/$directory/$subfolder/$document";

++$id;



$documentName= $_POST['document'][$i];

$id = $_POST['id'][$i];



//changing the name

if (file_exists($documentName))

{

rename ($document , $documentName) or die ("Could not rename file");

mkdir ($newDocumentName);

}

}

++$i;

}

}

What is suppose to be happening is i have a update page where people can update x amount of rows at one time, working great to send the information to the database. only thing these files are available in other places on the site, and so they are available dynamically. which means the physical directory/ document needs to be moved or altered to match the database.

pkcidstudio
04-27-2007, 09:59 PM
- solved this one -

pkcidstudio
05-15-2007, 03:31 PM
Something arise today that I wasn't noticing prior. When a submit is done, and
NO change has been made to the top item that is displayed in my table. that items
file gets deleted from the folder that it resides in. It only does it to this
item. I am wondering if any one has experienced this, or maybe knows why this
is happening. Below is the function that I believe is causing this error. Thanks
in advance.

// find out how many records there are to update
$documentMoveName_size = count($_POST['document']);

// start a loop in order to update each record
$i = 0;
while ($i < $documentMoveName_size)
{

// define each variable
$id = $_POST['id'][$i];
$document= $_POST['document'][$i];
$subfolder = $_POST['title'][$i];
$directory = $_POST['filetype'][$i];

$queryDocumentMove = "SELECT DISTINCT document, filetype, title FROM $tbl_name WHERE id='$id' ";
$resultDocumentMove = mysql_query($queryDocumentMove) or die("Invalid query: $queryDocumentMove");
while($row = mysql_fetch_array($resultDocumentMove))
{
$oldDocument = $row['document'];
$oldSubfolder = $row['title'];
$oldDirectory= $row['filetype'];
}

if ($documentMoveName_size = 0)
{
echo 'no change';
//rename("sys:apache2\htdocs\usa\docs/$directory/$subfolder/$document", "sys:apache2\htdocs\usa\docs/$directory/$subfolder/$document");
} else {
//echo $oldDocument;
rename("sys:apache2\htdocs\usa\docs/$oldDirectory/$oldSubfolder/$oldDocument", "sys:apache2\htdocs\usa\docs/$directory/$subfolder/$document");
}

++$i;
}
//die;
}