PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon May 25, 2020 12:04 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Tue May 31, 2016 3:29 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
Syntax: [ Download ] [ Hide ]
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.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Tue May 31, 2016 6:25 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
What do you mean "it fails"? What errors are reported? Have you checked that the files you're attempting to rename actually exist?

_________________


Top
 Profile  
 
PostPosted: Tue May 31, 2016 6:34 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
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.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Tue May 31, 2016 8:11 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
Check the log. Check the return value of the rename operation. Check the values of both rename arguments. Use file_exists.

_________________


Top
 Profile  
 
PostPosted: Tue May 31, 2016 8:40 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
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.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Tue May 31, 2016 8:43 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
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?

_________________


Top
 Profile  
 
PostPosted: Tue May 31, 2016 9:15 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
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.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group