Page 1 of 1
Why does this rename script only half work?
Posted: Tue May 31, 2016 3:29 am
by simonmlewis
Code: Select all
define('DS', DIRECTORY_SEPARATOR);
$image_dir = dirname(__DIR__) . DS . 'images' . DS . 'productphotos' . DS;
define('IMAGE_DIR', $image_dir);
define('IMAGE_DIRSMALL', IMAGE_DIR . 'small' . DS);
$photoprimaryname = isset($_POST['photoprimaryname']) ? $_POST['photoprimaryname'] : null;
$photoprimarynewname = isset($_POST['photoprimarynewname']) ? $_POST['photoprimarynewname'] : null;
if (isset($photoprimaryname) && !empty($photoprimaryname) && isset($photoprimarynewname) && !empty($photoprimarynewname))
{
$renameResult = rename(IMAGE_DIR . $photoprimaryname, IMAGE_DIR . $photoprimarynewname);
$renameResult2 = rename(IMAGE_DIRSMALL . $photoprimaryname, IMAGE_DIRSMALL . $photoprimarynewname);
// Evaluate the value returned from the function if needed
if ($renameResult == true) {
echo $photoprimaryname . " is now named " . $photoprimarynewname;
mysql_query ("UPDATE products SET photoprimary = '$photoprimarynewname' WHERE id = '$id'");
} else {
echo "Could not rename that file";
}
}
I'm using this script to run renaming tools, so files with spacing can be renamed without the space.
It works on the $renameResult", but on the one with the "small" subfolder, it fails.
It renames it in the database, and the top level image, but it just won't do the small one.
Yet, it works on another site with the same script.
Re: Why does this rename script only half work?
Posted: Tue May 31, 2016 6:25 am
by Celauran
What do you mean "it fails"? What errors are reported? Have you checked that the files you're attempting to rename actually exist?
Re: Why does this rename script only half work?
Posted: Tue May 31, 2016 6:34 am
by simonmlewis
Sorry I should have given more detail.
The files do exist, as it renames the file in /productphotos/.
It updates the entry in the database.
The file does exist in /productphotos/small/ because on the pages where there are the small thumbnails, they do show.
No errors that I can see on screen. It just renames the main file and the db, and where there was a thumbnail, I Get the cross showing.
Re: Why does this rename script only half work?
Posted: Tue May 31, 2016 8:11 am
by Celauran
Check the log. Check the return value of the rename operation. Check the values of both rename arguments. Use file_exists.
Re: Why does this rename script only half work?
Posted: Tue May 31, 2016 8:40 am
by simonmlewis
There is no log that I can find as it is local.
How do I check the return value? $renameResult2 always shows a 1, but then so does the other one!
The file 100% exists.
Re: Why does this rename script only half work?
Posted: Tue May 31, 2016 8:43 am
by Celauran
There's a log. I can't tell you where it is -- it's your system -- but there's a PHP log. Check Apache and PHP configs.
Is the target directory writable?
Re: Why does this rename script only half work?
Posted: Tue May 31, 2016 9:15 am
by simonmlewis
Sometimes I really wonder about my head.
It DOES work. The consumer page was looking for the images on the LIVE server!!! What a fool.