Problem with renaming folders
Posted: Wed Jan 28, 2009 3:46 am
Hallo friends,
I have a problem with renaming files and how that it goes:
Suppose we have a web page (e.g: http://www.mypage.com), and in that page we have a subpage called "Countries" in which we show the name of a country and 4 thumbs for each country. Also, in our Mysql DB, we have a table - also called countries - in which we store the name of the country and the path of the folder from which the supbage will take the thumbs for the specific country.
(The country table has 3 columns the: countryid, country, fotopath).
Now in the admin control panel we have a form in which the admin can add, rename or delete a country and thus it' s folder with thumbs.
The problem is focused in the rename function of the folder either the folder has thumbs or not.
Here i give you my steps
In the countries.php file when the admin push the button "rename" - of an existing country - in the "control countries" form, the form gets the countryid of the specific country, and add's it's value to a variable called cid and also has a textbox called "t1" - in which the admin add's the new name of the country (and so the new name of the already existing folder) - and posts these two variables (cid and t1) to the Rcountry.php file
In the Rcountry.php file i have this code:
$sql = "SELECT fotopath FROM COUNTRYT WHERE (countryid=\"".$_GET['cid']."\")";
$res = mysql_query($sql) or die("there is no path");
$row = mysql_fetch_array($res);
$oldpath = $row['fotopath'];
$oldpath = str_replace(' ',"\\",escapeshellcmd($oldpath));
/*When i store the path in the DB, Mysql removes automatikaly the "\" element from the string, so when i add a new country i
use the str_replace("\\"," ", string of path) in order to replace the "\" element with empty spaces - which Mysql doesn' t removes.
So when i want to recieve the path from the DB, i follow this procedure reversly by reblacing empty spaces with the "\" element
with the str_replace(" ","\\",string of path);
*/
$mypath = "..\\TWadmin\\fotoforeas\\Images\\". $_POST['t1'];
rename($odlpath,$mypath) or die("the folder hasn't been renamed");
$mypath = str_replace('\\'," ",escapeshellcmd($mypath )); // i explained the purpose of this function above
$sql = "UPDATE countryt SET country=\"".$_POST['t1']."\", fotopath=\"" .$mypath. "\" WHERE(countryid=\"".$_GET['cid']."\")";
mysql_query($sql) or die("we didn't update the DB");
header("Location://localhost/TWadmin/countries.php");
exit();
Now when i this file runs the function rename fails.
I would appreciate is smbd could correct my code (if there is any mistake) or show me another way to achieve my purpose
I have a problem with renaming files and how that it goes:
Suppose we have a web page (e.g: http://www.mypage.com), and in that page we have a subpage called "Countries" in which we show the name of a country and 4 thumbs for each country. Also, in our Mysql DB, we have a table - also called countries - in which we store the name of the country and the path of the folder from which the supbage will take the thumbs for the specific country.
(The country table has 3 columns the: countryid, country, fotopath).
Now in the admin control panel we have a form in which the admin can add, rename or delete a country and thus it' s folder with thumbs.
The problem is focused in the rename function of the folder either the folder has thumbs or not.
Here i give you my steps
In the countries.php file when the admin push the button "rename" - of an existing country - in the "control countries" form, the form gets the countryid of the specific country, and add's it's value to a variable called cid and also has a textbox called "t1" - in which the admin add's the new name of the country (and so the new name of the already existing folder) - and posts these two variables (cid and t1) to the Rcountry.php file
In the Rcountry.php file i have this code:
$sql = "SELECT fotopath FROM COUNTRYT WHERE (countryid=\"".$_GET['cid']."\")";
$res = mysql_query($sql) or die("there is no path");
$row = mysql_fetch_array($res);
$oldpath = $row['fotopath'];
$oldpath = str_replace(' ',"\\",escapeshellcmd($oldpath));
/*When i store the path in the DB, Mysql removes automatikaly the "\" element from the string, so when i add a new country i
use the str_replace("\\"," ", string of path) in order to replace the "\" element with empty spaces - which Mysql doesn' t removes.
So when i want to recieve the path from the DB, i follow this procedure reversly by reblacing empty spaces with the "\" element
with the str_replace(" ","\\",string of path);
*/
$mypath = "..\\TWadmin\\fotoforeas\\Images\\". $_POST['t1'];
rename($odlpath,$mypath) or die("the folder hasn't been renamed");
$mypath = str_replace('\\'," ",escapeshellcmd($mypath )); // i explained the purpose of this function above
$sql = "UPDATE countryt SET country=\"".$_POST['t1']."\", fotopath=\"" .$mypath. "\" WHERE(countryid=\"".$_GET['cid']."\")";
mysql_query($sql) or die("we didn't update the DB");
header("Location://localhost/TWadmin/countries.php");
exit();
Now when i this file runs the function rename fails.
I would appreciate is smbd could correct my code (if there is any mistake) or show me another way to achieve my purpose