Copying via PHP results in URL mismatch - php

I have a code which would copy a file from one location to another.When I try to access the copied file,I am receiving file not found error,but the file is actually present in that location.
Location of source file:codebase\assets\default_pages\
Location of file to be copied:codebase\site_users\general\test\
Source file:home.php
Destination file:test.php[Rename while copying]
Code:Test.php[location:codebase\models\user_entry\]
copy("../../assets/default_pages/home.php","../../site_users/general/test/test.php");
When I try to access test.php,it gives me following error,
/codebase/site_users/general/ravikanth/codebase/site_users/general/test/test.php
But when I create a file manually[without code]everything works fine.Thanks in advance for your help.

i think you must be having some sort of redirect inside your php file.
can you paste the content of the file which your trying to access after copying

It could be a simple file permission problem. Try chmod command. Maybe manually you are creating/copying with root but Apache or whatever the PHP runs on does not have a permission.

Related

I can't view the uploaded files in laravel

I have built an application using laravel that uploads pdf files to the public/pdfs/books/ folder. Then I am trying to create a pop up window that will display the uploaded file using the url.Bit while trying to view the file using my pop up box I am getting the following error.
Not allowed to load local resource: file:///C:/laragon/www/Uploader/public/pdfs/books/book.pdf
Can anyone suggest why I am getting this error? I even tried to load the file from another directory outside the application and got the same error. How Can I view the file from my application uploaded to folder
You shouldn't use the folder url like this. Because your application is running in local server So it should be able to view the file that starts with http.
To make the link for view use the following code in blade:
{{URL:to('/').'pdfs/abstracts/fillename.pdf'}}
Or use similar type of mechanism so the file is loaded with http protocol instead of from local directory starting with file:///C:
Can you view the file from browser?
file:///C:/laragon/www/Uploader/public/pdfs/books/book.pdf
If not, you should recheck your upload code.
Looks like permission issue, try chmod 775 -R * command in your /Uploader/public/pdfs directory. You could also try changing file permission in cpanel

Write permission of php file in server

I have created a php file which will open a text file(which resides in the same location along with the php file),and i also added some code thus i can change the content of the text file.It was working great in my local host but as soon as i upload the folder to a server i cant save the changed content to the file some permission related error is coming up.Is there any way thus i can forcefully change the content of the file in server?I mean is there any way thus this permission related issues can be overcome?
Access it via FTP and change the permissions to 755 which allows everyone to read / execute and only yourself to write.
Read more about permissions to find what best suits your requirements.

PhP download to root folder

If I have a php file on my root folder on my website, is there a way to go to a download line with that file and download the file to the directory where the php is rather than to the computer>
As #Cale_b said, no, not without FTP. The PHP file will execute if you try and get it through the browser. Why do you want to do that anyway?

Can't login to FTP site using PHP but can with Internet Explorer

I'm trying to access a URL like:
ftp.somesite.com/content/somefile.txt
Using login myname and pass mypass.
I can enter these in IE9 when they are requested and it opens the file right up. However, when I try this in PHP or Firefox I'm given a 550 error regarding the file /myname/content/somefile.txt.
What is wrong and why are both PHP and Firefox changing the file location to include myname as part of the file path?
ftp://username:password#ftp.somesite.com/content/somefile.txt
This is a valid URL. Sometimes FTP clients will put your username#hostname in the URL when you login. This isn't a problem, it is just for clarity, and also allows you to copy and paste that URL with the username.
When you log into FTP, your base directory may not be the same as your htdoc/web server directory.
What is the full file path for the file you wish to download?
Ex:
/root/somefile.txt
/home/user/test/somefile.txt
/var/www/site/content/somefile.txt
Just figured out how to resolve this in both PHP and Firefox.
To prevent the addition of the username to the directory structure, add another "/" to the start of the file path. This forces the root dir.
In other words:
ftp.somesite.com//content/somefile.txt

file uploaded via php: no such file or directory

i'm working on a website wherein the users can upload images (uses php 4.3.11). the files are uploaded with no problem as i can see them in the upload directory and i don't get any error message, but when i try to access the uploaded files via ftp, i get an error: no such file or directory. sometimes, i am able to access the file sometimes i get this error. what could be the problem here?
[update]
thanks for the help guys. i'm not familiar with the ftp daemon stuff. but i do access my files via ftp using FireFTP. the files are there but when try to download them or change the file properties, i get the said error. i also tried uploading a file in the folder through ftp and i was able to download it with no problem.
here is some of the code i'm working on, its kind of roundabout but i'll see on how to improve it.
my working directory is something like this www.domain.com/register/
and the upload directory is here www.domain.com/register/uploads/
users are required to register and upon sign-up, a folder is created for them in the uploads directory. i couldn't find a way to create a folder without having to be in the uploads folder itself so i redirect to a create-user-folder.php file in the uploads dir.
the file just contained this code:
$user_foldername = rawurldecode($_GET['name']);
mkdir($user_foldername);
header("Location: ../form.php"); // redirect back to the page
i checked and the created folder's permission is set to 775.
and here's part of the code i use in uploading ( /register/function/function.php ):
$path = "../uploads/$user_foldername/";
for($j = 0; $j < $num_of_uploads; $j++){
if(is_uploaded_file($_FILES[$file]['tmp_name'][$j])){
$filename = $_FILES[$file]['name'][$j];
copy($_FILES[$file]['tmp_name'][$j],$path.$filename);
}
}
i checked using FireFTP and the files are in the /uploads/user_foldername/ directory and its permission is set to 664. the strange thing is that when i try to download the files, at times there would be no problem at all but there are times when the error will appear.
[another update]
i added chmod() after the copy() function,
$filename = $_FILES[$file]['name'][$j];
copy($_FILES[$file]['tmp_name'][$j],$path.$filename);
chmod($path.$filename, 0755);
but i still get the error.
another thing is that when i access /register/uploads/user_foldername/ through the url, i can see all of the uploaded files and view them, but how is it that i can't access them via ftp?
thanks again!
This is either a permission issue, or a configuration error. Here are things you should try:
What are the permission of the uploaded files? Does the FTP user has access to these files? Have you tried logging in as the user the FTP daemon would use and see if you could read the file that way?
Do you really see the correct directory? Have you verified by putting a file in that directory yourself and downloading it? Have you used the ftp command ls to verify the presence of the folder/folders/files?
You might need to chmod the folder the files are in, or in some cases the files themselves.
try chmoding them to 775
You can chmod files and folders through PHP it's self, with the chmod function. Or, you could use a FTP program such as filezilla.
Also check to make sure the intermediate directories are also permissioned as 755, as all the directories in the path need to be executable to be traversed.
i just figured out the problem. it was all because of the file name having accented characters in it, which explains why i do not always get the error message :|
<sigh> i should have seen this earlier, but anyway i hope this helps in case someone ran into the same problem.
thanks again! i really appreciate it :)

Categories