The function move_uploaded_file() isn't working on my server and I really dont know why.
the error:
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to access MYADDRESS/img-19.png in MYADDRESS/index.php on line 660
I gave to the folder which I upload files chmod 777. any solution? im sure 100% the problem isn't in my code.
Make sure you have it in the $src, $dest order:
move_uploaded_file($_FILES["field"]["tmp_name"], 'foo.png');
Also, check PHP settings, especially safe_mode and base dir restrictions.
Side note: Don't chmod your folders to be world writable! Change the group of the folder to be that of the webserver, and use 775. Last thing you need is something like an SQL injection from MySQL writing a PHP file into that folder.
Related
I'm running Tesseract at Linux server, PHP 5.4. I uploaded main class file into classes/TesseractOCR.php, set chmod to 666 on and unfortunatelly it still returning warnings instead of any values from png file.
Here is my code:
require_once 'classes/TesseractOCR.php';
....
$tesseract = new TesseractOCR($file);
$tesseract->setTempDir('/absolute_path_to/temp/'); // temp folder have chmod 777
$tesseract->setWhitelist(range(0,9), '-+.'); // i'm trying to recognize phone numbers
echo $tesseract->recognize();
Warning:
Warning: file_get_contents(/absolute_path_to/temp/366108750.txt): failed to open stream: No such file or directory in /absolute_path_to/classes/TesseractOCR.php on line 236
I tried many ways with path to temp folder (and also without it), but I still gain nothing. I'll very appreciate any help or suggestion; I tried to google out solution but every one comes to set temp folder, which not helps me.
Many thanks in advance.
I was trying to upload a custom logo to my drupal site which runs on IIS 8 with PHP.
I got the following upload error :
" Warning: move_uploaded_file(temporary://logo.png): failed to open stream: "DrupalTemporaryStreamWrapper::stream_open" call failed in drupal_move_uploaded_file() (line 1642 of C:\inetpub\wwwroot\drupalfull\includes\file.inc).
Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\php25C3.tmp' to 'temporary://logo.png' in drupal_move_uploaded_file() (line 1642 of C:\inetpub\wwwroot\drupalfull\includes\file.inc).
File upload error. Could not move uploaded file."
Please help me. I have set both read and write permissions on IIS but still it does not work.
Create sites/default/files/tmp folder and give full permissions (777) and change 'Temporary directory' at admin/config/media/file-system.
I think it fixes yout problem.
Regards.
If you are running ISS8 (web server) then the file path is different then the default for Unix.
Make sure you have the temporary folder setup correctly on your settings in Drupal and the folder has write permissions.
You can follow this article at step 5 and 6.
Create the folder:
Drupal uses the Sites\Default\Files directory to store temporary files and therefore must be able to write and modify files in this folder.
Create the folder:
C:\inetpub\wwwroot\Drupal>md sites\default\files
http://www.iis.net/learn/application-frameworks/install-and-configure-php-applications-on-iis/install-drupal-on-iis
Your problem is most likely the permission problem inside drupal. Since you are using windows system, you need to make sure the folder sites/default/files have writable permission for the IIS server. Config the permission to be writable for all user and see if it is working and then limit the permission step by step until you feel comfortable.
I'm going to put another answer in here because I guarantee I'm going to forget how I fixed it!
Basically, on Windows, the default upload folder for PHP is C:\Windows\Temp. As part of the Drupal upload, it moves files from the PHP upload folder to the Drupal Temporary//: folder. There is an issue however in PHP whereby the PHP executable needs read permission to the full path to the uploaded files, so C:\Windows\Temp. If this is not given, it will error out and the file will not be moved.
Details are at http://php.net/manual/en/function.realpath.php which is a function call made deep in Drupal's upload file code.
My fix was to create a folder elsewhere, say C:\PHPTemp, and modify PHP's settings (session.save_path and upload_tmp_dir) to point to this folder instead. After giving IIS_IUSRS full control (overkill? probably!), I was then able to upload images!
I've been stuck on this code for days as I am hitting this error when I upload a file to the server. Its a windows server running on Apache
Tried various solutions but still receiving the error. I tried changing full permissions to everyone on that server.
I changed the default PHP upload tmp file to inside my application yet I am still having this error.
Warning: move_uploaded_file(C:\My_Workspace\ojs2002) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\My_Workspace\ojs\admin\include\fileupload.php on line 78
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\My_Workspace\ojs\tmp\phpCB78.tmp' to 'C:\My_Workspace\ojs2002' in C:\My_Workspace\ojs\admin\include\fileupload.php on line 78
// copy the file, making the destination directory if necessary
$filedir = 'C:/My_Workspace/ojs2002/'.basename($_FILES['articlefile']['name']);
chmod($_FILES["articlefile"]["tmp_name"], 0777);
chmod($filedir, 0777 );
move_uploaded_file($_FILES["articlefile"]["tmp_name"],$filedir);
The code would work fine on Linux servers but not on Windows.
Any help would be very much appreciated. Thank You.
I decided to switch from:
move_uploaded_file($uploaded_file, $file_path);
to
file_put_contents($file_path, file_get_contents($uploaded_file));
#unlink($uploaded_file);
The unlink might fail but I'm not too worried about that.
chmod won't work on Windows, as it uses a different type of permission system. Make sure the user Apache runs as has full write access to the folder you're trying to move the files to (right click and click on sharing or permissions depending on the version of windows)
I'm using move_uploaded_file() to upload images to the server, however it gives the usual error of:
Warning: move_uploaded_file(upload/file.png) [function.move-uploaded-file]:
failed to open stream: No such file or directory in
/home/newuser/public_html/model/account.class.php on line 39
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move
'/tmp/phpuLkUgE' to 'upload/file.png' in
/home/newuser/public_html/model/account.class.php on line 39
This is not permission based as I have set the folder to 777 with root access and ls -l displays it correctly as this.
755 /home/newuser/public_html/model
755 /home/newuser/public_html/model/account.class.php
777 /home/newuser/public_html/upload
PHP Line
move_uploaded_file($_FILES["photo"]["tmp_name"], "../upload/file.png");
The problem I think is down to the Owner/Group setting being configured incorrectly .. a while back I had all of my sites as subdomains in one account:
/home/olduser/public_html/subdomains/index.html
I then changed this and created a new user account to manage a separate website easier and just moved the files across ...
/home/olduser/public_html/subdomains
/home/newuser/public_html/index.html
The new folders in /home/newuser are now owned and grouped as newuser newuser but I think php may be running as nobody olduser so this could be causing the issue?
What can I try to fix this?
Permissions to a particular file / directory don't just apply on the directory itself, but on the whole path leading up to it.
Example:
/home/ - needs 'x' permission (execute)
/home/newuser/ - needs 'x' permission
/home/newuser/public_html/ - needs 'x' permission
/home/newuser/public_html/avatar/ - needs 'wx' permission (execute + write)
It was kind of touched on indirectly in Silver89's feedback under Jack's Answer, but not outright stated - so I wanted to provide an answer to what helped me with this issue which had me scratching my head for a long time. ;)
The best approach that I have found for the destination of move_uploaded_file() is to use the full absolute path. It can vary based on whether you are on a Unix\Linux server or Windows server, but this should give you the basic idea.
On my Unix server at work, you cannot use "../anything" but have to use the full absolute internal file path of /var/www/html/uploads/imagename.jpg.
So that is why your last test worked for you, Silver89 - because your server was probably trying to upload the image to http://yourservername.com/upload/file.png instead of http://www.yourservername.com/yoursubfolder/upload/file.png. It probably threw out the "../" part altogether and that folder didn't exist on the server.
You can find out what that full path name is by logging onto the server (terminal/ssh etc.) and issuing the 'pwd' command or by using PHP code and echoing the getcwd() command in a stripped php file in the folder where your images will go.
This site is helpful in figuring this out based on your server using different PHP Server Config Checking Functions - See the table midway down. You can simply echo these out to the screen such as:
echo $_SERVER["SCRIPT_FILENAME"].
This was a tough one for me so I hope this makes it a little easier for the next person to find - even if this is 8 months old. ;)
may i know what permission do i need to add, to allow test.php to able to write file into macos filesystem
PHP Error: <br />
<b>Warning</b>: file_put_contents(20090915203127.jpg) [<a href='function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: Permission denied in <b>/Library/WebServer/Documents/testphp/test.php</b> on line <b>8</b><br />
ERROR: Failed to write data to 20090915203127.jpg, check permissions
this is the error i get on leopard, i already chmod ugo+x for test.php
It's not the file that needs permissions, it's the process running PHP. Assuming you're using (Snow) Leopard in it's default state, you'll need to give the _www user write permissions to the given directory, or give the world write access (a less savoury idea). Both of these can be accomplished with a combination of chown and chmod.
You need to make sure the user the script is running under is allowed to write to the file trying to write to (i.e. 20090915203127.jpg, not the PHP script). If 20090915203127.jpg does not exist, you'll need to make sure the directory that file's going to is writable (by default this will be the present working directory).
You may need to read about chmod.
As far as I know you need root rights to be able to write directly to /Library. Is it absolutely necessary to write to this directory?
If you just write files to your own account, under /Users/accountname it should work (although that depends on the user who is executing the php script).
You need to make the target file / directory writable to the web server. test.php is not into that...