LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-17-2011, 12:18 PM   #1
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,211

Rep: Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612
PHP to rename file


ive tried:
Code:
//Variables:
$file='my_filename.txt';
$file2='new_filename.txt';

exec ('mv $file $file2');
//(no result)

rename ($file, $file2);
//(no result)

echo getcwd() . "\n";
///var/www/html/
So, what am i missing here?
 
Old 03-17-2011, 12:22 PM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,305

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Permissions?

Put this in the beginning to get more info:

error_reporting(E_ALL);
 
1 members found this post helpful.
Old 03-17-2011, 12:26 PM   #3
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,211

Original Poster
Rep: Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612
Quote:
Originally Posted by Guttorm View Post
Permissions?

Put this in the beginning to get more info:

error_reporting(E_ALL);
Fixing the file permissions worked for running it from the command line. I am still in the situation though, it isnt working from the web frontend, with this:

Code:
<?php
error_reporting(E_ALL);

$test = $_POST["filename"];

$test2 = substr($test, 9);

rename("$test", "$test2");

?>
 
Old 03-17-2011, 12:29 PM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,305

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
PHP Code:
rename($oldfile,$newfile) or die(posix_strerror(posix_get_last_error())); 
 
1 members found this post helpful.
Old 03-17-2011, 12:31 PM   #5
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,211

Original Poster
Rep: Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612
Quote:
Originally Posted by Guttorm View Post
PHP Code:
rename($oldfile,$newfile) or die(posix_strerror(posix_get_last_error())); 
That outputs:

SUCCESS

But the filename isn't changed.
 
Old 03-17-2011, 12:41 PM   #6
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,305

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Hmm. It didn't set errno. What is the contents of $_POST['filename']? Maybe add some output:

echo "rename(\"$test\", \"$test2\");";

Also, you can set display_errors in php.ini of your webserver. It's turned off by default.
 
1 members found this post helpful.
Old 03-17-2011, 01:43 PM   #7
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,211

Original Poster
Rep: Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612
Quote:
Originally Posted by Guttorm View Post
Hmm. It didn't set errno. What is the contents of $_POST['filename']? Maybe add some output:

echo "rename(\"$test\", \"$test2\");";

Also, you can set display_errors in php.ini of your webserver. It's turned off by default.
Got it.

The directory was permissed wrong.

Thanks for the help.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to rename a file with php? ranvir03 Programming 3 11-23-2010 02:39 AM
replace line in CSV file and rename file connected to that name wademac Linux - Newbie 3 07-15-2009 01:09 PM
how to rename a file with weird characters in php michaeljoser Programming 4 06-29-2009 10:39 AM
Need to replace a file with a newer version but keep the old file via a rename Joe_P Linux - Newbie 4 04-30-2009 03:51 PM
how to rename a file and copy a file in a shell zach014 Linux - Newbie 6 11-23-2006 09:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration