$file = 'my/path/to/htaccess/location/.htaccess';
$htaccess = file($file);
$ht = fopen($htaccess,'a');
fwrite($ht,"deny");
fclose($ht);
I'm trying to modify the .htaccess file via functions.php, the CHMOD is set to 777, any ideas?
Edit:
Just enabled errors:
Warning: file() [function.file]: URL file-access is disabled in the server configuration in /home/tfbox/domains/ibrogram.com/public_html/themes/beta/wp-content/themes/beta/functions.php on line 133
Warning: file(http://themes.ibrogra.com/beta/.htaccess) [function.file]: failed to open stream: no suitable wrapper could be found in /home/tfbox/domains/ibrogram.com/public_html/themes/beta/wp-content/themes/beta/functions.php on line 133
Warning: fopen() [function.fopen]: Filename cannot be empty in /home/tfbox/domains/ibrogram.com/public_html/themes/beta/wp-content/themes/beta/functions.php on line 135
Warning: fwrite(): supplied argument is not a valid stream resource in /home/tfbox/domains/ibrogram.com/public_html/themes/beta/wp-content/themes/beta/functions.php on line 137
Warning: fclose(): supplied argument is not a valid stream resource in /home/tfbox/domains/ibrogram.com/public_html/themes/beta/wp-content/themes/beta/functions.php on line 139
This
$file = 'http://'.$_SERVER['SERVER_NAME'].'/beta/.htaccess';
makes the requested path a http path.
That doesn't make sense - you want to use a file path.
You could use
$file = $_SERVER['DOCUMENT_ROOT'].'/beta/.htaccess';
instead.
Related
I am developing a website that includes functions with file upload. This was working perfectly on localhost, but once I uploaded the site to my server it fails.
I have the following code to handle the file upload:
case "upload_to_gallery":
/*******************************
**** UPLOAD TO GALLERY ****
*******************************/
if ($con->checkLogin() && isset($_FILES['uploaded_files'])) {
$gallery_name = $_POST['gallery_name'];
for ($i = 0; $i < count($_FILES['uploaded_files']['name']); $i++) {
list($width, $height, $type, $attr) = getimagesize($_FILES["uploaded_files"]['tmp_name'][$i]);
if ($_FILES['uploaded_files']['type'][$i] == "image/png"
|| $_FILES['uploaded_files']['type'][$i] == "image/jpeg"
|| $_FILES['uploaded_files']['type'][$i] == "image/gif"
) {
$imgPath = "../files/img/galleries/" . $gallery_name . "/" . $_FILES['uploaded_files']['name'][$i];
$thumbPath = "../files/img/galleries/" . $gallery_name . "/thumbs/" . $_FILES['uploaded_files']['name'][$i];
move_uploaded_file($_FILES['uploaded_files']['tmp_name'][$i], strtolower($imgPath));
$filehandler->makeThumbnails($imgPath, $thumbPath, 300, 215);
}
}
header('location: '.MAINPATH.'/galleri/'.$gallery_name.'?billeder_uploadet');
And the errors i am getting, when trying to upload some files (images) on the server is:
Warning: move_uploaded_file(../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php on line 35
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phptu17Hf' to '../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg' in /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php on line 35
Warning: getimagesize(../files/img/galleries/Test/1383204_10200900060289437_410542691_n.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php on line 158
Warning: Division by zero in /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php on line 159
Warning: Division by zero in /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php on line 159
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php on line 162
When I try to upload 0 files to the server it gives me this error:
Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php on line 26
Which I don't think makes sense, as I am checking if any files has been sent through..
I thought it might have something to do with permissions on the server, but all the relevant folders is set to '755'.
I hope someone might know what the problem could be.
Any help will be greatly appreciated.
Check carefully your errors.
Warning: move_uploaded_file(../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php on line 35
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phptu17Hf' to '../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg' in /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php on line 35
Warning: getimagesize(../files/img/galleries/Test/1383204_10200900060289437_410542691_n.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php on line 158
You have both test and Test in your paths.
Remember that Linux is case-sensitive for file and folder names. Windows is not. That might explain why it worked on your dev environment and why it didn't anymore on your prod server.
So pick either one of them and stick with it (I wouldn't recommend to use uppercase characters in your paths though).
Warning: include(/home/sarvadcu/public_html/paradisetourism.co.in/wp-content/themes/midway/functions.php): failed to open stream: Permission denied in /home/sarvadcu/public_html/paradisetourism.co.in/wp-settings.php on line 329
Warning: include(): Failed opening '/home/sarvadcu/public_html/paradisetourism.co.in/wp-content/themes/midway/functions.php' for inclusion (include_path='.:/usr/local/altphp54/lib/php') in /home/sarvadcu/public_html/paradisetourism.co.in/wp-settings.php on line 329
Warning: Cannot modify header information - headers already sent by (output started at /home/sarvadcu/public_html/paradisetourism.co.in/wp-settings.php:329) in /home/sarvadcu/public_html/paradisetourism.co.in/wp-includes/pluggable.php on line 1196
It is problem with template path ,on here template function file not get proper path from wp-setting.php.
try to check out that path Or function file path .on theme activation.
when theme activate that time it find function.php file but it not get correctly so that.this error come.
I have the following Warnings which SHOULD be there, but is there a way to stop them writting to the page without actually disabling Warnings globally?
Warnings:
Warning: file_get_contents(E:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(F:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(G:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(H:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(I:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(J:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(K:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(L:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(M:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(N:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(O:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
Warning: file_get_contents(P:/connected.txt): failed to open stream:
No such file or directory in C:\xampp\htdocs\ppa\test.php on line 19
PHP Function:
//Check if the connection file is present on each drive
function scanDrives() {
//Possible drives
$letters = "DEFGHIJKLMNOP";
$letters = str_split($letters);
$code = md5("FMbHSBTMTXhu3TWp");
//Check for a certain file on each device
foreach($letters as $x) {
$file = file_get_contents($x.":/connected.txt"); //This is what causes the error as the file can't be found.
if ($file != false) {
$file_code = split(":", $file);
//Check if the file has the correct pass code
if($file_code[0] == $code) {
//Successful, return pass value and device letter and set name
echo (1).",".$x.",".$file_code[1];
}
}
}
}
Thanks.
Don't just blindly open the file with file_get_contents. Check to see if it exists first.
if(file_exists($x.":/connected.txt")){
$file = file_get_contents($x.":/connected.txt");
// ...
}
I agree with #Rocket Hazmat,
but to answer your question - in PHP you can use Error Control operators .. Specifically you can use the # sign to ignore errors.
Simple Example
$file = #file_get_contents("file_doesnt_exist.php"); // wont throw any errors.
Try to put "#" before the function that gives you the warning!
http://us3.php.net/manual/en/language.operators.errorcontrol.php
I have a problem with a php code.
Folder name what-counter This folder contains a file with the following php code named counter.php also the hitcount.txt file.
<?php
$filename = '../what-counter/hitcount.txt';
$handle = fopen($filename, 'r');
$hits = trim(fgets($handle)) + 1;
fclose($handle);
$handle = fopen($filename, 'w');
fwrite($handle, $hits);
fclose($handle);
// Uncomment the next line (remove //) to display the number of hits on your page.
echo $hits;
?>
The following php code is used in root directory files also in files from folders which echo's the hits.
<?php include("../what-counter/counter.php"); ?>
The problem
The code works in the files in folders but not in the files that are directly in the root directory.
Example: index.php is in the root directory
Using this code i get this Warning
<?php include("what-counter/counter.php"); ?>
Warning: fopen(../what-counter/hitcount.txt) [function.fopen]: failed to open stream: No such file or directory in /home/what/public_html/what-counter/counter.php on line 4
Warning: fgets(): supplied argument is not a valid stream resource in /home/what/public_html/what-counter/counter.php on line 5
Warning: fclose(): supplied argument is not a valid stream resource in /home/what/public_html/what-counter/counter.php on line 6
Warning: fopen(../what-counter/hitcount.txt) [function.fopen]: failed to open stream: No such file or directory in /home/what/public_html/what-counter/counter.php on line 8
Warning: fwrite(): supplied argument is not a valid stream resource in /home/what/public_html/what-counter/counter.php on line 9
Warning: fclose(): supplied argument is not a valid stream resource in /home/what/public_html/what-counter/counter.php on line 10
And using this code i get this Warning
<?php include("../what-counter/counter.php"); ?>
Warning: include(../what-counter/counter.php) [function.include]: failed to open stream: No such file or directory in /home/what/public_html/include/footer.php on line 31
Warning: include(../what-counter/counter.php) [function.include]: failed to open stream: No such file or directory in /home/what/public_html/include/footer.php on line 31
Warning: include() [function.include]: Failed opening '../what-counter/counter.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/what/public_html
/include/footer.php on line 31
What can i do to the $filename url and <?php include("../what-counter/counter.php"); ?> to get it to work in files in root directory as well as folders?
Either:
Include relative the the file: __DIR__.'/../somefile';/__DIR__.'/somepath/somefile';
Include relative to a known dir: $_SERVER['DOCUMENT_ROOT'] is often used, as is a PROJECT_DIR-like define() in your bootstrap code.
Change the working directory to a known/static dir chdir('/some/dir');. Not recommended as calling code may not expect this.
Sounds like absolute vs relative file problems...
Try replacing:
$filename = '../what-counter/hitcount.txt';
With, depending on where the file is located exactly, either of:
$filename = __DIR__ . '/what-counter/hitcount.txt';
$filename = dirname(__DIR__) . '/what-counter/hitcount.txt';
Or (if you're on an old php install) either of:
$filename = dirname(__FILE__) . '/what-counter/hitcount.txt';
$filename = dirname(dirname(__FILE__)) . '/what-counter/hitcount.txt';
According to fopen documentation, in some modes it will create the file if it does not exist, but in my situation, I've checked all 'w', 'w+', 'x' and 'x+' modes but it's just throwing warnings at me and it cannot create the file.
It's my code:
$this->handle = fopen($this->log_name, 'w');
and what I get:
Warning: fopen(D:\xampp\htdocs\farid\logs\error.php) [function.fopen]: failed to open stream: No such file or directory in D:\xampp\htdocs\farid\libraries\error\log.php on line 34
Warning: fwrite() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\farid\libraries\error\log.php on line 66
Warning: fclose() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\farid\libraries\error\log.php on line 27
And I'm working in windows environment.
Check if the path to the logfile exists, it creates a file, not a directory.
Also check if the user, which runs xampp, has access to the folder you specified.