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?)
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
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?
I'm using this code to upload file to my server. It works just fine if I am uploading to same server but it does not upload if I am uploading to subdomain which is in the same server but different cpanel and everything.
Here is my code:
<?php
$url = 'http://www.indiancinemagallery.com/gallery/vaani-kapoor/Vaani-Kapoor-at-Radio-Mirchi-Stills-(9)9678.jpg';
$img = '/home/path_A/something/test/flower.gif';
file_put_contents($img, file_get_contents($url));
?>
I have given correct path for subdomain.
If I give path of same server from where file is being executed it will upload otherwise it will not upload. The main problem is mysql is there in main server so i want to execute the file from main server and store the photo in subdomain and update the details in main server.
Warning: (flower.gif: failed to open stream: Permission denied in /
This is likely a file permission problem. Your script must have write access to wherever $img points to on the server.
Can you try adding the following at the top of your PHP script to see what, if any, errors/warnings that PHP is throwing?
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
That should tell you if it is failing to write to the file and give you some info.
If after changing permissions, you still cannot write to that location, I imagine it is enforced by your web server management software (Web Host Manager, cPanel, etc.) and how it configures the file space. At that point, you might want to try using PHP's FTP functions (preferably SFTP for security): http://php.net/manual/en/wrappers.ssh2.php
I have 2 servers, the main and the test one. They're on the same network.
The users have files in a shared folder, to which both have access, using a virtual directory with read access.
The PHP.ini are pretty much the same on core and extensions.
I'm using MPDF to generate a PDF, and in the HTML there is a URL to an image in the shared folder. If I echo the HTML, it shows image, if I do $mpdf->Output(); it fails with this fopen() error:
failed to open stream: A connection attempt failed because the
connected party did not properly respond after a period of time, or
established connection
Both servers have allow_url_fopen but only the test server can generate the PDF well.
It looks like a permission issue. You have 2 users with read access to a virtual directory, and you get an error with $mpdf->Output(); that looks like it may require write access.
I try to upload a file through PHP's ftp_put function, like so:
ftp_put($this->conn_id, $rempath, $locpath, $mode);
However I get the error "Cannot STOR." Nothing more. The FTP-connection is OK since I can download files using the same settings and ftp_get(). The script should be OK as well since it works fine on my local setup but not on my public server.
What can I try to make it work? I Googled but found nothing of worth.
You should first check to make sure that you are able to upload using a regular FTP client. I see you say "there's no problem withmy FTP-client" but in the initial request you said you are able to download files successfully and failed to mention a successful upload. I believe you will find that uploading with a client will fail too because that message is the output of FTP and not PHP. Whether or not it is a permissions issue remains to be seen, but it is unlikely a PHP issue. Do a little more research on FTP error 550.
Sounds like a permissions error. Are you sure you have permissions to upload the file to the location you are trying to put it at? If you try to do the upload manually via FileZilla or something does it work?
You should check to be sure you have write permissions on the directory into which you are trying to put the file(s).
Cannot STOR is a permission issue. Doublecheck the permissions for the FTP user.