PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
dharprog
Forum Contributor
Posts: 126 Joined: Fri Oct 27, 2006 12:20 am
Post
by dharprog » Mon Jul 30, 2007 11:36 am
Hi
I have tried so many times to work it out. But i am unable to do it.
I have tried to copy a file from one directory to another directory but its working in my local computer but after uploading this to the godaddy server its not working for me.
Code given below.
Code: Select all
if($work=="add_site")
{
$short = $_POST['short_name'];
if(mkdir("../$short/", 0777))
{
$file = "../includes/index.php";
$newfile = "../$short/index.php";
if(copy($file, $newfile)=='1'){
$str = "insert into table_site(short_name,display_name,tot_lines,block) values('".$_POST['short_name']."','".$_POST['display_name']."','".$_POST['tot_lines']."',0)";
$str = mysql_query($str);
if(mysql_affected_rows()>=1)
{
$_SESSION['msg'] = "Successfully site added";
header("Location:admin_sites.php");
}
}
else
{
$_SESSION['msg'] = "Failed to copy file";
header("Location:add_site.php");
}
}
}
Please let me know if anybody has come across this problem and got the solution.
Thank you very much.
Last edited by
dharprog on Sun Aug 05, 2007 12:07 am, edited 1 time in total.
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Mon Jul 30, 2007 11:42 am
Slightly off-topic, but..
Code: Select all
$short = $_POST['short_name'];
if(mkdir("../$short/", 0777))
DO NOT DO THAT. That's a really, really massive security issue.
dharprog
Forum Contributor
Posts: 126 Joined: Fri Oct 27, 2006 12:20 am
Post
by dharprog » Mon Jul 30, 2007 11:46 am
Hi
Thanks for your reply but could you please tell me is there any other way to do it?
Thank you.
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Mon Jul 30, 2007 12:02 pm
If it works on your computer and not the server, you have issues with file / folder permissions.
dharprog wrote: Thanks for your reply but could you please tell me is there any other way to do it?
Filter and validate ALL user input. ALL of it.
dharprog
Forum Contributor
Posts: 126 Joined: Fri Oct 27, 2006 12:20 am
Post
by dharprog » Mon Jul 30, 2007 12:08 pm
Hi
I tried with setting different permissions like 777 , 755, 646 etc... but not working.
Folder gets creating except file copying only not working.
I set the 777 so all the permissions are allowed like read, write and execution.
Even though write permission set file copying is not working for the above script.
All the input is correct.
Thank you.
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Mon Jul 30, 2007 12:14 pm
Turn on your error reporting and display errors or view the error log. Also might want into setting a parameter in mkdir to true, which will create full paths if they don't exist.
dharprog
Forum Contributor
Posts: 126 Joined: Fri Oct 27, 2006 12:20 am
Post
by dharprog » Mon Jul 30, 2007 12:29 pm
Hi
I dont know how to turn on error reporting. Could you please tell me and where to do this?
I'm getting upto creating a directory if not exists, but i'm getting problem at file copying to that directory.
Thank you.
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Mon Jul 30, 2007 1:18 pm
echo $file and $newfile and check to see if $file exists using file_exists(); and is_file();
You'll need to research how to turn on error reporting and display errors. Are these both linux computers?
dharprog
Forum Contributor
Posts: 126 Joined: Fri Oct 27, 2006 12:20 am
Post
by dharprog » Mon Jul 30, 2007 9:19 pm
Hi
My local computer is windows xp and using wamp server.But server is linux.
Thanking you.
dharprog
Forum Contributor
Posts: 126 Joined: Fri Oct 27, 2006 12:20 am
Post
by dharprog » Thu Aug 02, 2007 11:28 pm
Hi
what i came to know is when make a directory in server through php programme with permissions setting 777, i could see that the user for the folder is 'apache', if i make a folder through ftp or in the server itself the the user of the folder is 'ftp user id'.
What is this i don't understand. Please if anybody know then tell me, May be the solution would be here.
Could you please tell me how to handle Hosting Server side directories and files with file operations?
Is there any best tutorial for that?
Thank you.
iknownothing
Forum Contributor
Posts: 337 Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia
Post
by iknownothing » Fri Aug 03, 2007 12:14 am
back to the original topic..
is that valid, or should it be..
dharprog
Forum Contributor
Posts: 126 Joined: Fri Oct 27, 2006 12:20 am
Post
by dharprog » Fri Aug 03, 2007 12:25 am
Hi
If you dont mind one thing i would like to remind you that:
if it doesnt work then how can i say/post here that its working in local computer?
And now i tested and that its giving the return value as 1. And that to its working for TRUE also.
Thank you very much.