Situation:
Ubuntu 16.04
PHP 7
NFS share from an OpenVMS host
Trying to copy a file from the NFS share to a local directory.
The PHP copy() function copies the file, but the resulting local file has a bunch of junk at the end of it. I suspect it's the allocated but unused area at the end of the physical OpenVMS file, but haven't proved that.
Using copy( 'ftp://...' ) results in
failed to open stream: FTP server reports 502 SIZE is unimplemented
file_put_contents( ..., file_get_contents( ... )) does work, though.
Can somebody please explain to me why file_get_contents() gets the correct data and copy() does not?
Related
I am developing a web application using laravel, and the application requires me to create a pdf file and save it to be downloaded later.I have successfully created the file from view using laravel-snappy and i can download it on the browser.The problem is that; when i try to save the file in a network shared drive using the file_put_contents function, I get the error captioned on the question's title.
When I change the path from network drive, to let say disk D:/test of the server, the file is successfully saved in that location.
I have tried the following ways to achieve it as below
$saving = "Z:/test";
Z is the network drive (drive of th shared folder)
1.By using barry laravel snappy facade
$pdf = PDF::loadView('file',compact('data'));
When I return it as below it works
return $pdf->download($fileName);//download the file
But when saving it in the path it gives me the error I mentioned above
$pdf->save($savePath);//saving the file
Using the file_put_contents function
$output = $pdf->output();
file_put_contents($savePath,$output);
Still getting the same error
3.Using the copy function
In the same drive/disk but different folders it works
$path1 = "D:/files";
$path2 = "D:/test";
copy($path1,$path2);
But when i change $path2 to the shared network drive/folder
$path1 = "D:/files";
$path2 = "Z:/test";
copy($path1,$path2);
It does not work and I get a different error as shown below
copy(Z:/test/39361_1657094148_elicense.pdf): failed to open stream: No such file or directory
When i change from Z:/test to IP of the shared folder as \\x.x.x.x\test it gives me another error as copy(\\x.x.x.x\test/39361_1657094148_elicense.pdf): failed to open stream: Invalid argument
I have tried this for 3 days now but nothing is working When I save to that shared folder/drive
I really need help. Anyone with an insight on how I can get out of this problem I will appreciate
Thanks in Advance
the issue was with the permission, my application had no right to write to that network shared folder
The solution was to open the directory and then save the file
I find the solution from this link https://www.codedwell.com/post/21/reading-file-list-from-a-mapped-windows-network-drive
Thanks for the insight #ADyson
I have a copy function per say:
<?php
copy ( "$source" , "$destination" );
?>
The code does create a copy succssfully however the $destination (or copied file) is left blank. if i open it it is empty unlike the $source file.
The file size is 0b.
My situation:
nginx/1.10.0 (Ubuntu)
PHP 7.0.13-0
ubuntu0.16.04.1
The file permissions for the code processing file is 0777
The permission for the source file is 0777
The file permission for the destination file after being copyed (the blank one ) : 0644.
Obviously no control over the permission before copying.
Anyone know the reason for this and how to make the php copy() function copy the file with the original file contents?
Best regards,
AT
Ok so i seemed to solve this apparently my server ran out of disk space.
Makes sense. should have known.
I'm using two computers (both connected to one network) and one of them has XAMPP. I'm trying to upload files to the one with XAMPP in it (the files are from the other computer). But I always end up having the 'No such file or directory' error even though I have the correct path. But when I use the path from the computer with XAMPP, even when I'm using the other computer, the system works just fine. Can anyone help me?
P.S. I'm using PHP copy() function because the file path is coming from an excel file.
Here's the part of my PHP code:
$original_file_name = objWorksheet->getCellByColumnAndRow(5,$i)->getValue();
// Example of the cell value: C:\Users\ComputerWithoutXAMPP\Desktop\scanned documents\SO 2010\#1.jpeg
$ext = pathinfo($original_file_name, PATHINFO_EXTENSION);
$file = time().substr(md5(microtime()),rand(0,26),5);
// UPLOAD THE FILE DECLARED IN EXCEL
copy($original_file_name, 'uploads/docs/'.$file.'.'.$ext);
You can use copy() to upload a file to another machine, or from another machine, but to access the remote machine, the appropriate argument to copy (source or dest) has to be a URL. The code you've posted is trying to copy the file to a local "uploads/docs/" directory, it's doesn't even appear to aware of another machine.
While what you're looking to do may be technically possible, I haven't the foggiest idea how you'd go about it: it seems rather Rube Goldberg to me. The ftp:// wrapper would probably work, if FTP is set up properly on the XAMPP server.
How big is the file you're trying to send? If it's small enough, you may have better luck either encoding and sending the content itself or uploading the file with curl to an upload-catching script on the XAMPP side
I'm trying to load data from a CSV on my Windows PC into a database, something I've successfully done previously. fopen can't find my input file.
Here's the specific code I'm having trouble with:
<?php
ini_set('track_errors', '1');
$handle = fopen("C:/Users/Sam/Documents/test.csv", 'r') or die("can't open file: $php_errormsg");
?>
The error printed is:
[function.fopen]: failed to open stream: No such file or directory
The file definitely exists, and I get the same problem on Unix machines. How do I fix this?
Windows 7 (and Vista?) only lets a user access his own home directory and does not allow Apache (or other users) to. Unfortunately, this is a major headache, and I would suggest that you just move the file somewhere public.
This type of behavior is easier to fix in Linux, but you're still better off moving the file out of your directory into some path where Apache has read access.
I am trying to upload image file from my one server to another remote server (owned by me). but its giving me error
Warning: move_uploaded_file(http://www.mysite.org/photo/color-sample-colorize12-10-2010-09-14-09.jpg)
[function.move-uploaded-file]: failed to open stream: HTTP wrapper does not support writeable connections.
Thanks for any suggestion or help in advance
You cant do that.... You need the sites to be on the same physical server and have the directory youre moving to have the proper permissions and be mapped in to both sites.
You could however use ftp or cURL functions to actually upload the file to the remote server, just not move_uploaded_file.
You need to get the file from the remote server using something like file_get_contents and then save it to a file on the local server using file_put_contents, or ftp, or curl if you have the permissions. You can't just copy a file like you would if it was on the same server. (I assume this is what you're trying to do, right?)