Log in

View Full Version : Resolved Server Setting or Typo?



bluewalrus
12-20-2010, 12:48 AM
My code is being executed here "/public_html/rename.php" with this


rename("products/$dir/$value", "products/$dir/$submitted");
rename("products/$dir/tmb/$value", "products/$dir/tmb/$submitted");


my error message is


rename(products/Helmets/H200_LP1.jpg,products/Helmets/H200_LP1.jpg) [function.rename]: No such file or directory in /home/theleat1/public_html/rename.php on line 11

this part
(products/Helmets/H200_LP1.jpg,products/Helmets/H200_LP1.jpg)

Makes me think the server may be parsing the rename incorrectly because there is a space there.

The figures are located in /public_html/products/Helmets and /public_html/products/Helmets/tmb.

my full code is:


<?php
session_start();
$_SESSION['logged_in'] = "yes";
$dir = $_GET['dir'];
foreach($_POST as $submitted) {
$value = key($_POST);
$unset_value = key($_POST);
$value = preg_replace('/(.*?)_jpg/', "$1.jpg", $value);
echo "original= products/$dir/$value" . " newname= products/$dir/$submitted<br />";
echo "original= products/$dir/tmb/$value" . " newname= products/$dir/tmb/$submitted<br />";
rename("products/$dir/$value", "products/$dir/$submitted");
rename("products/$dir/tmb/$value", "products/$dir/tmb/$submitted");
unset($_POST[$unset_value]);
}
?>

On another side question does $_POST change . to underscores when it is inputted as the key for example figure1.jpg become figure1_jpg. Thanks.

traq
12-20-2010, 04:00 AM
the space is missing in the error message because it's optional (PHP ignores it anyway).

Two things to check:
1) use absolute filepaths instead of relative ones - e.g., try $_SERVER['DOCUMENT_ROOT'].'/products/'.$dir.'/'.$value.

2) make sure the directory exists, and that the path to it is correct (I know that's obvious, but it's the problem nine times out of ten) and that your script has read/write permissions for every directory in the path.