简体   繁体   中英

Rename file codeigniter

I want to move a file to another directory in my server. So I use rename, but i have an issue :

Message:rename(localhost:8888/asset/upload/pdf/161115_1231_maj.pdf,localhost:8888/asset/upload/del/pdf/161115_1231_maj.pdf): No such file or directory

But, when i copy paste the link in my browser, the link is good, so i don't understand why rename doesn't work. I also tried to use copy, move_uploaded_file, with absolute path or not.

Thanks for your time

Use the filepath, not the URL. In other words, /var/www/html/asset..... (or where ever it is) instead of "localhost"


EDIT...

Based on your comments you say you're using MAMP, but your stuff is located in a WAMP folder. MAMP is for Mac only and doesn't run on Windows and WAMP is for Windows only and doesn't run on Mac, so your first step is to figure out which one your using and place your files in the correct directories because the two are not compatible with each other..

If you want your file to work on both the server and your development machine without changing paths you can always determine the absolute path with PHP..

Assume you have a file structure like this

/webroot
   index.php
/uploads
   myfile.pdf
   /del

You can get the full path to the current file like this

$Full_path_to_current_file = realpath(dirname(__FILE__));

If you put that in your index file, it would look like this: /full/path/to/my/webroot

Now you can simply do

rename("$Full_path_to_current_file/uploads/myfile.pdf", "$Full_path_to_current_file/uploads/del/myfile.pdf");

that way you don't have to have two separate versions of the file with different paths.


EDIT 2

The next probable cause is lack of permissions. Make sure that PHP has access to the file in question. Run this in the command line and see if that helps (obviously use your real path though)

sudo chmod -R 777 /path/to/webroot

Don't do that on the server though, if you have to do it on the server just change the permission of the file itself. The easiest way to change the permission of a file on the server is to use FileZilla. Just FTP into the server, right click on the remote file and choose "file permissions." Then you can set the correct permissions as needed.

您应该使用引号:

Message:rename("localhost:8888/asset/upload/pdf/161115_1231_maj.pdf","localhost:8888/asset/upload/del/pdf/161115_1231_maj.pdf"): "No such file or directory"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM