The php code grabs values from a form and writes it to flat file. This code works locally but when I place it on the host I get the the two errors. Local instance doesn't require a config.php in the directory but the host file does.
error1: states that there is no config.php
error2:I have to specify a path but if
? - what do I put in the config file so it allows me to create the flat file or can I reference the file same how??
any help would be appreciated.
CODE:
<html>
<head>
<title>test</title>
</head>
<body>
<?php
include('config.php');
$user = $_GET["name"];
$message = $_GET["message"];
print("<b>Thank You!</b><br />Your information has been added! You can see it by <a href=savedinfo.php>Clicking Here</a>");
$out = fopen( $_SERVER['DOCUMENT_ROOT'] . '/flatfile/test/' . $user . '.txt', "a" );
if (!$out) {
print("Could not append to file");
exit;
}
fputs ($out,implode,("\n"));
fwrite($out,"<b>$user</b><br />$message<br /><br />");
fclose($out);
?>
</body>
</html>
ERROR:
1
Warning: include(config.php) [function.include]: failed to open stream: No such file or directory in /home/user1/flatfile/sendinfo.php on line 7
2
Warning: include() [function.include]: Failed opening 'config.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/user1/flatfile/sendinfo.php on line 7
You have 2 ways: create config.php or remove include.
Are you sure the config.php file is in the right directory you can check if the file exist and then include like this
if (file_exists('config.php')) {
include('config.php');
}
http://php.net/manual/en/function.file-exists.php
Related
Hello all this is a simple question which is already there in stack overflow but I tried all the possible answers still it's not fixed
I need to include config file which is under assets folder i tried the following code
include_once '../config.php' ;
am getting error like this
Warning: include(assets/config.php): failed to open stream: No such file or directory in E:\xampp\htdocs\project\assets\handler\ContactHandler.php on line 4
Warning: include(): Failed opening 'assets/config.php' for inclusion (include_path='E:\xampp\php\PEAR') in E:\xampp\htdocs\project\assets\handler\ContactHandler.php on line 4
kindly suggest me a possible way to include config file in ContactHandler.php
ContachHandler.php
<?php
include_once 'E:\xampp\htdocs\project\assets\config.php';
echo "ddddd";
exit;
include (CONTROLLER.'ContactController.php');
$form = $_POST['form'];
$cnt_controller = new ContactController();
switch ($form)
{
case 'AddContact':
$cnt_controller->AddContact($_POST);
break;
case 'ContactUs':
$cnt_controller->ContactUs($_POST);
break;
}
?>
Check to see if your include path changed and check file/folder permissions.
Try out this code:
<?php
$config_path = '../config.php' ;
if (file_exists($config_path)){
require_once $config_path;
}
else {
$config_path = 'config.php';
if (file_exists($config_path)) {
require_once $config_path;
}
else {
$config_path = '../../config.php';
require_once $config_path;
}
}
echo "ddddd";
echo $config_path;
exit;
?>
For testing set static path:
include_once 'E:\xampp\htdocs\project\assets\config.php';
Hope this helps!
I want to move example.txt file on my server (/var/www/tmp) to different destination (/var/www/tmp/dir). I want to have this file only in one destination in which is file moved, so only one file on server. I have tried many commands but I wasn't sucessful. Can you help me with this issue? Thanks.
Source code:
<html>
<body>
<?php
// variables from the form
$blogentry = $_POST['blogentry'];
// creating or opening the file in append mode
$dataFile = "example.txt";
$fh = fopen($dataFile, 'a');
// writing to the file
fwrite($fh,"". " " . $blogentry . " " . "\n\n");
fclose($fh);
?>
</body>
</html>
You would use PHP's rename() function to move files (the name of the function can be a little confusing).
rename("/var/www/tmp/file.txt", "/var/www/tmp/dir/file.txt");
You can probably just use the rename() function. From http://php.net/manual/en/function.rename.php:
rename("var/www/tmp/example.txt", "/var/www/tmp/dir/example.txt");
Hello so i have a simple upload system in php and i want to upload my files to ftp server but when i try to it doesnt work i get these two errors:
Warning: move_uploaded_file(/userfiles/grega): failed to open stream: No such file or directory in /srv/disk3/1618233/www/netdisk.co.nf/upload.php on line 19
Warning: move_uploaded_file(): Unable to move '/tmp/phpVtApVM' to '/userfiles/grega' in /srv/disk3/1618233/www/netdisk.co.nf/upload.php on line 19
and there is folder userfiles/grega on the ftp server please help me out
the code:
<?php
require_once 'core/init.php';
if($_POST[submit]) {
$name = $_FILES['upload']['name'];
$temp = $_FILES['upload']['tmp_name'];
$type = $_FILES['upload']['type'];
$size = $_FILES['upload']['size'];
if($size <= 5000000){
$user = new User();
if(!$user->isLoggedIn()) {
Redirect::to('index.php');
}
$uploads_dir = '/userfiles';
$username = ($user->data()->username);
move_uploaded_file($temp,"$uploads_dir/$username");
Session::flash('home', '<h3>Datoteka je bila naložena!</h3>');
Redirect::to('mojprofil.php');
} else{
echo "Napaka!";
}
} else {
header("Location: mojprofil.php");
}
?>
You say this:
there is folder userfiles/grega
But the error says this:
move_uploaded_file(/userfiles/grega)
Those are two very (even if subtly) different paths. Note also where you define the path in your code:
$uploads_dir = '/userfiles';
The code is looking for a folder called userfiles in the root of the entire file system, not just in the website. Perhaps you meant to do this?:
$uploads_dir = 'userfiles';
i have a problem with the move_uploaded_file function this is the problem:
Warning: move_uploaded_file(/imagenes/Icon.png) [function.move-uploaded-file]: failed to >open stream: No such file or directory in /home/decc98/public_html/php/insert.php on line 6
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpIBBh5U' >to '/imagenes/Icon.png' in /home/decc98/public_html/php/insert.php on line 6
Insercion exitosa
Other stuff, i speak spanish so part of my code is in spanish... Anyways, my code is:
<?php
include "conexion.php";
$ruta = "/imagenes";
$archivo = $_FILES['imagen']['tmp_name'];
$nombreArchivo = $_FILES['imagen']['name'];
move_uploaded_file($archivo,$ruta."/".$nombreArchivo);
$ruta=$ruta."/".$nombreArchivo;
$texto = $_POST['descripcion'];
$id = rand(1,200);
$insertar = mysql_query("INSERT INTO tablaUno VALUES('".$id."','".$ruta."','".$texto."')");
if ($insertar) {
echo "Inserción exitosa";
}else{
echo "Fallo en la inserción";
}
?>
Please if anyone can help me I would appreciate it!
You need to use a relative path instead of an absolute path.
For example:
$ruta = "imagenes";
leaving out the / at the beginning of your folder name, if you're using your script from the root.
Or, something like:
$ruta = "../imagenes";
depending on the script execution's location.
Note: Using / is mostly used for an (server) absolute path, something to the affect of:
/var/user/user123/public_html/imagenes
I have this code to move my uploaded file to a specific directory:
if (isset($_FILES["image"]["name"])){
if (!is_dir('pf/' . $uid)) {
mkdir('pf/' . $uid);
$large_image_location = "pf/" . $uid;
}else {
$large_image_location = "pf/" . $uid;
}
chmod ($large_image_location, 0777);
move_uploaded_file("$userfile_tmp", "$large_image_location/$userfile_tmp");
}
However that gives the following error:
( ! ) Warning: move_uploaded_file(pf/BfyhieniKJGGqTNm/C:\wamp\tmp\phpF08A.tmp) [function.move-uploaded-file]: failed to open stream: Invalid argument in C:\wamp\www\mingle\upload_dp.php on line 26
Any help on how to sort this out would be greatly appreciated!
This is 90% of your woes:
move_uploaded_file("$userfile_tmp", "$large_image_location/$userfile_tmp");
You using the moved to path at the beginning of the upload path. Try:
move_uploaded_file("$userfile_tmp", "$large_image_location/".$_FILES['image']['name']);
That should work better.
The error itself is pretty clear, pf/BfyhieniKJGGqTNm/C:\wamp\tmp\phpF08A.tmp is not a valid filename.
Don't change the contents of $_FILES[n]['tmp_name'] (or $userfile_tmp for that matter), since it will always contain the full path to the uploaded file.