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
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 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 form where users can upload images. I know how to do it with HTML/PHP and I know that I have to move the temp file to the permanent directory. Well this all works well when my file that processes the form, is in the root directory. But, I would like to have it work within another directory, on the same server.
The Structure is this:
ROOT
>images
>mobile
>upload.php
I would like to have the file put inside images, which is outside of the "mobile" directory.
My current upload path that does not work is:
define('UPLOADPATH', 'images/');
So essentially I need to go back one directory and then into images. How can I do this?
You need to add a .. To move to the parent directory. See this resource for more information
How can we move the one file from one folder to another folder without copy function in PHP.
In php copy function used to copy the file from one folder to another folder. But in my case I don't use copy function for move the file from folder to another folder.
You can try and make use of php rename function. It will move the file if a new directory was specified in the new move to filename. Just ensure that the permission are correct when moving and creating new folders and files.
rename("path1/file.txt", "path2/file.txt");
PHP RENAME
Attempts to rename oldname to newname, moving it between directories
if necessary. If newname exists, it will be overwritten.
If you do not want use PHP copy() function for some reason, you can do this like:
system('cp /path/to/src_file /path/to/dst_file');
for *nix systems, and
system('copy /path/to/src_file /path/to/dst_file');
for Windows
Suggest using rename().
http://php.net/manual/en/function.rename.php
rename('/dir1/old_dir/old_name.txt','/dir1/new_dir/zzz_name.bak');
I have a simple php image upload form that saves the images in a temporary folder, lets call it temp, and when the image is approved by me I manually copy it to the album folder.
My question is, if there is a way for someone or I don't know, a search engine maybe to find "guess" my temp folder and what images are inside ( before approve ).
You wrote it yourself:
The temp is inside public_html
Doesn't that answer your question?
If this is not desirable, create a .htaccess file inside the temp folder, with this content:
Deny from all
It depends on the location of the temp folder. If the folder lies outside the root directory of your server its not discoverable but if it lies inside the root directory it is discoverable. However you can limit the access to your temp folder if its inside the root of the server through htaccess. Or you can place a index.php file inside the folder with a header redirect so that no one can see the file(image) list.