I'm getting the following error while uploading a zip archive.
Warning: ZipArchive::extractTo(C:\xampplite\htdocs\testsite/wp-content/themes/mytheme//styles\mytheme/Thumbs.db) [ziparchive.extractto]: failed to open stream: Permission denied in C:\xampplite\htdocs\testsite\wp-content\themes\mythem\uploader.php on line 17
The thing I can't quite figure is that I don't see a thumbs.db file in either the zip archive or the destination folder that was created (the upload still processes, I just get these errors).
The function is below, line 17 is commented...
function openZip($file_to_open) {
global $target;
$zip = new ZipArchive();
$x = $zip->open($file_to_open);
if($x === true) {
$zip->extractTo($target); //this is line 17
$zip->close();
unlink($file_to_open);
} else {
die("There was a problem. Please try again!");
}
}
Looks like just a warning. I would ignore it. I'm betting the error happens when it tried to overwrite the thumbs.db file in the extraction directory.
Alternatively, use getNameIndex to get a list of files, filter thumbs.db and use the second parameter of extractTo to filter the files.
http://www.php.net/manual/en/function.ziparchive-getnameindex.php
http://www.php.net/manual/en/function.ziparchive-extractto.php
This path is all messed up
C:\xampplite\htdocs\testsite/wp-content/themes/mytheme//styles\mytheme/Thumbs.db
I guess this might be windows issue.
can you add a line above line 17 saying
echo $file_to_open; exit;
and tell us what it says when you try to upload file?
Assuming that the mangled path works, then there is a thumbs.db in the destination directory (by default a hidden file), and/or your script does not have permission to write to that file/directory. Windows is very big on spitting out "permission denied" when a file is in use by another process, rather than saying "In use by process XXX".
Related
I'm very new here but I'm facing an issue on one of my website with fopen().
$file="//".$_SERVER['SERVER_NAME']."/myfile".date("Ymd").".txt";
if (!file_exists($file)) {
$fp=fopen($file,"w+");
}
$fp=fopen($file,"r+");
And the error message :
fopen(mydomain/myfile20160629.txt): failed to open stream: No such file or
directory in /mydomain/myphpfile.php on line 24
What's funny is that I sometimes get an error message, sometimes not, depending what file use this. And I still got this message when the file is created...
Do you have any idea ?
Try set path : $file="//".$_SERVER['DOCUMENT_ROOT']."/myfile".date("Ymd").".txt";
but before that, move your file in directory $_SERVER['DOCUMENT_ROOT']
Within my script I need to connect to ftp and download few zips files and then extract them in a directory. I have already got this implemented and it works as expected when I run the script through browser but when the crontab run this script it throws me error that it failed to extract file. I tried to research but I had no luck I don't understand the reason for this.
Below is the error that I am getting:
A PHP Error was encountered
Severity: Warning
Message ZipArchive::extractTo(/home/name/files/complete//filename.txt): failed to open stream: Permission denied
Filename: controllers/import.php
Line Number: 66
Script:
$txt_file: "/home/name/files/complete/Data.zip";
$server_txt_file = "/TXT/Data.zip";
if (ftp_get($ftp_conn, $txt_file, $server_txt_file, FTP_BINARY))
{
$zip = new ZipArchive;
if ($zip->open($txt_file) === TRUE)
{
$zip->extractTo('/home/name/files/complete/');
$zip->close();
unlink($txt_file);
}
}
I am trying to fix this for days now but I can not figure out what the issue is.
The error is telling you everything you need to know:
failed to open stream: Permission denied.
So your php process has no permission to write to the specified folder. So you should change the permissions of specified folder.
I made a website a couple of year ago which has worked fine till now.
now, when I try to load an image from the backend it raises me some warning and the Image fails to be moved in the destination directory.
here is the warning I get
Warning: move_uploaded_file(path/image_name.jpg): failed to open
stream: Permission denied in
D:\inetpub\webs\remote_directory\php_script_name.php on line 184
Warning: move_uploaded_file(): Unable to move
'C:\PHPVersions\PHP55\uploadtemp\php418A.tmp' to 'path/image_name.jpg'
in D:\inetpub\webs\remote_directory\php_script_name.php on line 184
here is the line giving me the warning
if (!move_uploaded_file($_FILES['img_'.$pos]['tmp_name'], 'path/'."part_of_image_name".$_FILES['img_'.$pos]['name'])) {
$msg = "<p>Error loading image!!</p>";
break;
}
it does not even print the error message.
I tried to change permissions on directory (and all subdirs and files) via ftp but I'm not sure it succeded because it was giving me the following message
Comando: SITE CHMOD 740 Photo4.jpg.
Risposta: 500 'SITE': command not
understood
(by the way I read somewhere that it does not fix the problem. However the guy said he solved by using some magic which is not working for me - or I'm misunderstanding how to do it)
Everything worked until a few days/weeks ago (the customer wasn't clear on that point) so I just wanted to know if this is a kind of known issue or what (and a possible solution), since after a littlebit of research I could not find anything usefull.
try this, but first create a directory named uploads in the root directory:
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
Found out to solve the problem by using the control panel of site hosting provider to change manually permissions on directory.
I have been working on a upload file that works fine on localhost (windows) but wont work on my linux server I rent. I want it to move it to a subdir '/files' from where the file is.
it gives the errors:
Warning: move_uploaded_file(/home/taalhulp/domains/taalhulpmanager.nl/public_html/files/6) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/taalhulp/domains/taalhulpmanager.nl/public_html/Gegev_Dossier.php on line 66
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpFMaeAs' to '/home/taalhulp/domains/taalhulpmanager.nl/public_html/files/6' in /home/taalhulp/domains/taalhulpmanager.nl/public_html/Gegev_Dossier.php on line 66
Here is a simplified version of my code
$FotoMap = '/home/taalhulp/domains/taalhulpmanager.nl/public_html/files/' ;
if ($_POST['type'] == 'add' & strlen($_FILES['FileUpload']['name']) > 0 && strlen($_POST["GivenFileName"]) > 0 )
{
if (move_uploaded_file($_FILES['FileUpload']['tmp_name'], $FotoMap . $file_name_id))
{
$_SESSION['echo'] = 'succes';
}
else
{
$_SESSION['echo'] = 'fail';
}
}
it says permission denied but is that because I do something wrong or because i need to contact my provider to tell him to enable that, maybe you I can enable that myself?
Make sure that /home/taalhulp/domains/taalhulpmanager.nl/public_html/files/'s permissions are set to 0777.
I do not recommend doing that as it opens a bunch of security issues. You would be better finding out on which user or group the script is being run and modify the directory to be owned by that user instead.
you probably don't have permissions (PHP engine / apache webserver) to access the directory for temporary uploads. try to set your custom temp path.
I am php page everything was working fine till today morning. Now the page is not uploading any selected file. All that I keep getting is the following error message:
Warning: move_uploaded_file(upload/BrainStream_2009_06_25_23041.zip) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xampp\htdocs\vectorization\admin\jobs_edit.php on line 146
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Documents and Settings\Admin\Local Settings\Temp\php1B2.tmp' to 'upload/BrainStream_2009_06_25_23041.zip' in C:\xampp\htdocs\vectorization\admin\jobs_edit.php on line 146
File could not be uploaded. Please select a valid file.
File Name:BrainStream.zip
I have written following code:
$uplfile = $_FILES['uploadfile']['name'];
$upltmp = $_FILES["uploadfile"]["tmp_name"];
if(!empty($uplfile))
{
$ext = explode(".", $uplfile);
$upload_date = date("Y_m_d"); //use this variable to change file name to avoid conflict with same name files
$upload_dir = "upload/";
$file_name=$ext[0]."_".$upload_date."_".rand(0, getrandmax()).".".$ext[1];
(move_uploaded_file($upltmp,$upload_dir.$file_name))
}
I have XAMPP stack installed on my PC which is running WinXP, has 3 GB RAM and ample of Hard disk space.
No matter which size file I select it always give error.
What must be wrong in this code?
Interesting syntax in the last line. The error indicates the problem is in that line and either the source file or destination directory is missing. Since the first one is automatically generated, make sure that C:\xampp\htdocs\vectorization\admin\upload exists and is writable.
#phihag,
Thanks for the hint. One of the new developer while studying the source had by mistake remove (../) in the $upload_dir variable assignment.
$upload_dir = "upload/"; //this is wrong
Actually it was set as
$upload_dir = "../upload/"; //this works but accidentally edited by another developer
What a lamer I am. I could not spot the problem.
Anyways thanks once one for your help to solve my problem.
looks like your problem could be that you're using forward slashes for your upload directory but on windows this would be a backslash, you also need to make sure that the upload directory is relative to the script. if not provide a full path.
A good tip to prevent the slashes issue is to use the DIRECTORY_SEPARATOR constant
One of two things - either
There is no upload directory
There is no file php1B2.tmp
This may seem obvious, but be sure to double check your php.ini
file_uploads = On
upload_tmp_dir = "C:\xampp\tmp"
upload_max_filesize = 64M
What might be useful for you to do is a quick check to ensure the file has been uploaded successfully e.g.
switch ($_FILES["cv"]["error"])
{
case UPLOAD_ERR_FORM_SIZE:
// handle error
case UPLOAD_ERR_INI_SIZE:
// handle error
case UPLOAD_ERR_PARTIAL:
// handle error
case UPLOAD_ERR_NO_FILE:
// handle error
case UPLOAD_ERR_CANT_WRITE:
// handle error
}
Its a better way of handling the errors you may encounter when uploading files.