I want to move a file from a folder to another folder on s3 but it is not moving to destination folder correctly. My code is below:
$old_path = "media_manager/omm/pic.jpg"
$new_path = "media_manager/omm/mypics/pic.jpg"
Storage::disk('s3')->move($old_path, $new_path)
It returns true and image file disappeared in old(source) folder but it is not showing up in destination(new) folder. I dont know why? I am using ajax to do this.
Plz help in this regard. Thanks
is the mypics folder exists on AWS S3 Bucket?
if no try to add the folder "mypics" manually and make sure that you have the permission to write he file inside of it
Related
I want to set my wordpress files to upload to /home/public_html/images instead of /wp_content/uploads, I have gotten to the point that it gives me the correct url for /home/public_html/images but I have to move the new files from /wp_content/uploads to /home/public_html/images for it to work
I have tried changing the upload path in wp-options.php but that just makes a subdirectory in my sites folder called public_html and puts the image there instead of actually putting it in /home/public_html/images
Try going to the wp_config.php file and adding this line of code:
define('UPLOADS', 'images');
This should put the images in a folder under /public_html instead of the typical /wp_content folder.
https://developer.wordpress.org/apis/wp-config-php/#moving-uploads-folder
I am trying to move an S3 file to a different directory in S3.
This is my code:
Storage::disk('s3')->move("https://my-s3-url.s3.aws.com/old-path/image.png","/new-folder/123/image.png");
The problem with this is I am getting this error:
League\Flysystem\FileNotFoundException : File not found at path: https://my-s3-url.s3.aws.com/old-path/image.png
But, when I checked that file in the browser, that file really exists.
I am also certain that when I uploaded that file before, I used s3 as the Storage::Disk().
What seems to be the problem here? TIA!
I just realized my own mistake here.
I solved this by not putting the entire AWS S3 URL of the old URL. So instead of putting this:
https://my-s3-url.s3.aws.com/old-path/image.png
It should only be this:
/old-path/image.png.
So my code looks like this:
Storage::disk('s3')->move("/old-path/image.png","/new-folder/123/image.png");
Hope this helps anyone.
I am new to PHP but have experience in .net. I need to know a way to save images uploaded to a PHP page in a subdirectory of that page and return its path. I have checked and not found a way to give permission to an existing subdirectory in PHP. I am using wamp for development.
passed subdirectory in file_put_contents with the image file name.
got full path and appended the subdirectory.
$ImagePath = __DIR__.'/driverimages/'.$ImageName ;
file_put_contents($ImagePath, base64_decode($data->profilepic));
I know that if I create a directory from a PHP script with 0774 permission I can write to it. But I need to write to an existing subdirectory and return the image path so that it can be used in the front end to show the image.
I need to be able to write to a subdirectory from the current directory and return the path of the written image file.
$ImagePath = __DIR__.'/driverimages/'.$ImageName;
mkdir(dirname($ImagePath),777);
file_put_contents($ImagePath, base64_decode($data->profilepic));
I have a project with CODEIGNITER where I have to upload files that is running well in localhost. But problem started when I uploaded the file into linux cpanel .file is not uploading also I have to find image from the folder that I did with the $_SERVER['DOCUMENT_ROOT'].'/project/sliderImages/'; but that also not working in cpanel . i am unable to solve the problem !
Can anyone please help me ? Thanks in advance
Locally my file upload folder location is
C:/wamp64/www/admin/sliderImages
and in cpanel its location is
public_html/admin/sliderImages
here admin is my project folder name under which there are all codeigniter file and folder .
i used upload path in codeigniter is
$config['upload_path'] = './sliderImages/';
and to find all images in that folder i used
$path = $_SERVER['DOCUMENT_ROOT'].'/admin/sliderImages/';
$files = glob($path.'*'); // get all file names
so tell me or give me any link that how can i upload and fetch file from folder with codeigniter in cpanel that i did in localhost !
also i have 755 folder permission for the folder in cpanel .
when i uploaded my project in cpanel and trying to upload a image in the folder it's showing an error like
Array ( [error] =>
The upload path does not appear to be valid.
)
why not try using relative path from index.php as all of your code will be executing from index.php. So try
$path = 'admin/sliderImages/';
$files = scandir($path); // get all file names
start with config file
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'];
This will make your upload path to be base_url('admin/sliderImages');
Let CI sort the urls and don't forget to endit the .htaccess file to reflect server configs
In my WordPress the visitors can upload files like texts and this files go in this path
C:\xampp\htdocs\www\wordpress\wp-content\uploads\temporary, After validating I need to insert this files in this path C:\xampp\htdocs\www\wordpress\wp-content\uploads\2014\10 like attachment , Should I using wp_insert_attachment or wp_handle_upload() ?
I don't know if this is related to wordpress because I do not have a slightest idea about it. But in php, you use the copy() function to copy a file from one folder to another. And if you want to remove the file from the temporary folder, you are looking for the unlink() function for deleting a file