So the scenario is, I have an ecommerce site which involves users uploading files & details, the links to the files & the text of the details is saved into a text file. All this stuff is uploaded into a temporary folder.
The payment system I have integrated is Paypal. I have Paypal send a response to the IPN. In this file, I send some emails, but I also wish to move the files into a permanent folder and thus edit the links in the text file. But I can't seem to access the files properly.
This is my error codes:
file_get_contents( ../uploads/tmp/file/*FILE NAME HERE*.doc) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in /home/*username here*/public_html/*name*/*dir*/ipn.php on line 103
PHP Warning: file_put_contents( ../uploads/tmp/file/*FILE NAME HERE*.doc) [<a href='function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: No such file or directory in /home/*username here*/public_html/*name*/*dir*/ipn.php on line 103
PHP Warning: copy( ../uploads/tmp/file/*FILE NAME HERE*).doc) [<a href='function.copy'>function.copy</a>]: failed to open stream: No such file or directory in *link to ipn.php* on line 106
//This is my code
if ($key == 'Book File '){
$oldBookFileName = $result['Book File '];
$oldBookLink = str_replace('*BASE URL IS HERE*', '../',$oldBookFileName);
if (strpos($result['Book File '],'/tmp/') !== false) {
$newBookFileName = str_replace("/tmp/","/perm /",$oldBookFileName);
$newBookLink = str_replace('*BASE URL IS HERE*', '../',$newBookFileName);
}
//update file names in file & move files
//include ('updatefile.php');
file_put_contents($oldBookLink, str_replace($oldBookFileName, $newBookFileName, file_get_contents($oldBookLink)));
//copy/move files from tmp to perm
copy($oldBookLink, $newBookLink);
}
I've tried using the full path (www.example.com/dir/file.php) and using the relative path (../dir/file.php). Also, all the links are correct, I echo'ed them out in an email and they are correct.
Anyone know what Im doing wrong? Something totally retarded? Please help.
Thank you.
You likely have the relative path wrong. Try using realpath() to see what path PHP is actually using.
For the full path you need to use the path on the server, not the http URL. So something like /home/username/public_html/dir/filename.doc instead of www.example.com/dir/filename.doc
Related
I am getting file path from MySQL which is stored in my db to read .txt file content but cannot figure out what's going wrong.
$myfilepath=$record['CodeFilePath']; // here getting file path
$content=file($myfilepath); // giving it to function file()
foreach($content as $val){ //reading the content from file .txt
echo $val;
}
The error is
WARNING: FILE(TUTORIAL1.TXT ): FAILED TO OPEN STREAM: INVALID ARGUMENT IN
Ensure that you don't have spaces around the name using....
$content=file(trim($myfilepath));
Also if your using a *nix platform, file names are case sensitive, so TUTORIAL1.TXT is not the same file as tutorial1.txt. Windows is a lot more forgiving.
I am writing some php script to update the code on my sites. In order to do that I have written the following lines which checks for the update version and bring the name from where I use to distribute my updates ans then creates the link of that name. I have done something like this.
$filename = "http://www.hf-live.com/codeupdate/Get_Files_Name.php";
$contents = file_get_contents($filename);
echo $contents;
I am getting this error
failed to open stream: No such file or directory.
Even though the file is present still I am getting the same error. I have turned on my allow_url_fopen to on. The above code is working from my local host but not from the server. I have to update a major bug fix and I am stuck.. Please someone help me soon..
remove extra .php from url
$filename = "http://www.hf-live.com/codeupdate/Get_Files_Name.php";
You will get error if you are doing this way...
$filename = "marynyhof.com/Info.php"; // will give you error, which exactly you are getting
use full url like this
$filename = "http://www.marynyhof.com/Info.php"; //will work
I am trying to upload file on ftp.
here is my code
$jname= "Accounts of Biotechnology Research";
if (!is_dir('/Trade/upload/ '.$jname)) {
mkdir('/Trade/upload/ '.$jname); // line 63
}
move_uploaded_file($_FILES["submission_file"]["tmp_name"], "/Trade/upload/$jname/" . $dup_name ); // line 67
Trade is a folder inside public_html folder.
When i am uploading a file it gives me a warning like,
Warning: mkdir() [function.mkdir]: No such file or directory in /home/my_username/public_html/Trade/upload.php on line 63
Warning: move_uploaded_file(/Trade/upload/Accounts of Biotechnology Research/76164762-sm.pdf) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/my_username/public_html/Trade/upload.php on line 67
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phphZXp0O' to '/Trade/upload/Accounts of Biotechnology Research/76164762-sm.pdf' in /home/my_username/public_html/Trade/upload.php on line 67
First:
You have a space here mkdir('/Trade/upload/ '.$jname);. Suppose you should have mkdir('/Trade/upload/'.$jname); (same for is_dir)
Second:
Ensure that you can write into Trade/upload directory.
Third (and I suppose that is the real problem):
It looks like you are trying to upload into a directory with full path:
/home/my_username/public_html/Trade/upload/, but your code will try to create a directory with full path:
/Trade/upload/.
You need to change
if (!is_dir('/Trade/upload/ '.$jname)) {
mkdir('/Trade/upload/ '.$jname); // line 63
}
to
if (!is_dir('upload/'.$jname)) {
mkdir('upload/'.$jname); // line 63 (or maybe there should be Trade/upload, but suppose current working dir will be /home/my_username/public_html/Trade, so only upload/)
}
Another option is to force mkdir to create directories recursively:
mkdir('/Trade/upload/'.$jname, 0755, true);
But in that case, files will be uploaded into /Trade/upload/... instead of /home/my_username/public_html/Trade/upload/...
There are two things you should be aware of based on the error messages you received. I'm guessing /Trade isn't the root path on your machine since it's clear in the error that your actual path is /home/my_username/public_html/Trade/, so the first adjustment should be
$root_path = "/home/my_username/public_html/Trade/upload/";
The second adjustment I'd suggest is that you avoid pathnames with space in them:
$jname= "Accounts of Biotechnology Research"; //could be changed to
$jname= "Accounts_of_Biotechnology_Research"; //$jname = str_replace(" ","-",$jname) OR
$jname= "Accounts-of-Biotechnology-Research"; //$jname = str_replace(" ","-",$jname)
Finally take note of the space character on the following lines, they affect you final result:
if (!is_dir('/Trade/upload/ '.$jname)) { //AND
mkdir('/Trade/upload/ '.$jname);
}
Note the [space] between upload/ '.$jname in both strings.
Heres my code within functions.php:
<?php
$id = 10;
$html = file_get_contents("inc-star-rating.php?id=$id");
echo $html;
?>
Heres the contents of inc-star-rating.php:
<?php
$id = $_GET['id'];
echo "<div>I have the ID of $id</div>";
?>
They are both in the same directory on my server, so why am I getting the following error?:
Warning: file_get_contents(inc-star-rating.php?id=10)
[function.file-get-contents]: failed to open stream: No such file or
directory
inc-star-rating.php?id=10 is probably not the right file name. It probably does not exist like this in the filesystem.
If you mean to fetch a URL via an HTTP request, you need to explicitly give the full URL as it's accessible through the web server:
file_get_contents("http://localhost/inc-star-rating.php?id=$id")
Whether this is a good idea or not is a different topic though. Usually you want to require other PHP files and execute their code by calling functions in them, not make a new HTTP request.
I want to create File that have Full permission dynamically, that means every change for ID of session create new file .
Unfortunately I faced some problem .
Warning: fopen(test.txt) [function.fopen]: failed to open stream: Permission denied in /home/teamroom/public_html/1/3.php on line 2
Warning: fwrite(): supplied argument is not a valid stream resource in /home/teamroom/public_html/1/3.php on line 3
Warning: fclose(): supplied argument is not a valid stream resource in /home/teamroom/public_html/1/3.php on line 4
code :
<?php
session();
$member_Id=$_SESSION['user_id'];
if (isset($member_Id)){
$file = fopen("test.txt","x+");
fwrite($file,"test");
fclose($file);
}
?>
can you help me ?
or can you tell another way to do this idea ?
It would appear that the process PHP is running as (often the web server, e.g. www-data) does not have write permissions for the folder you're trying to create the file in
(e.g. /home/teamroom/public_html/1/).
You also should be doing error checking on the fopen() call. Then there's the security assect to think of.
you have no permissions to access directory. Use php-function chmod ("/somedir/somefile", 755); or change directory permissions by ftp-client.
And why are you trying to open file with x+ if you need only writing:
Modes:
r - Reading only, beginning of file
r+ - Reading and writing, beginning of file
w - Writing only, beginning of file
w+ - Writing and reading, beginning of file
a - Writing only, end of file
a+ - Writing and reading, end of file
x - Create and open for writing only, beginning of file
x+ - Create and open for reading and writing, beginning of file
If the file does not exist and you use w, w+, a or a+ it will attempt to create the file.
I think you can use w+ or a+
And for your another problem:
<?php
$fp = fopen ('/path/to/file', "r");
while (!feof ($fp))
{
$value = fgets($fp);
if(!empty($value))
{
//Here do what you want with your value
}
}
?>
This was string-by-string reading code. Also you can use file_get_contents(); php-function and work with it lika string.
P.S> Sorry for my english