Permission error with rename()
-
Hello everyone. I’ve just got an interesting error when creating a function that deletes the original image after uploading. This is the error code I got:
Warning: rename(/storage/content/49/208749/mydomain.com/public_html/wp-content/uploads/sites/25/,/storage/content/49/208749/mydomain.com/public_html/wp-content/uploads/sites/25/2015/09/XperiaZ5RangeBanner-1500x550.jpg): Invalid argument in /storage/content/49/208749/mydomain.com/public_html/wp-content/plugins/mydomain-image-settings/mydomain-image-settings.php on line 27 1069
As you can see I have a multisite which I tried on. Then I tried on my local server and got this:
Warning: rename(C:\xampp\htdocs\mydomain_dev/wp-content/uploads/,C:\xampp\htdocs\mydomain_dev/wp-content/uploads/2015/09/image.jpg): Access is denied. (code: 5) in C:\xampp\htdocs\mydomain_dev\wp-content\plugins\mydomain-image-settings\mydomain-image-settings.php on line 27 140
The function code:
function replace_uploaded_image($image_data) { // if there is no large image : return if (!isset($image_data['sizes']['large'])) return $image_data; // paths to the uploaded image and the large image $upload_dir = wp_upload_dir(); $uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file']; // $large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file']; // ** This only works for new image uploads - fixed for older images below. $large_image_location = $upload_dir['basedir'] . '/'.$image_data['sizes']['large']['path']; // delete the uploaded image unlink($uploaded_image_location); // rename the large image rename($large_image_location,$uploaded_image_location); // update image metadata and return them $image_data['width'] = $image_data['sizes']['large']['width']; $image_data['height'] = $image_data['sizes']['large']['height']; unset($image_data['sizes']['large']); return $image_data; } add_filter('wp_generate_attachment_metadata','replace_uploaded_image');
My current permissions are 755 in wp-content and uploads folder. So what is happening here? Why doesn’t this work? Any ideas?
- The topic ‘Permission error with rename()’ is closed to new replies.