So I am using .php pages now to use a .txt include for the navigation.
Here is the live page I am working on :
http://glustik.com/essex/index.php
It seems to display line 27 code errors, not sure how to get this include to work.
Anyone care to point me in the right direction for this one?
Warning: include(txt) [function.include]: failed to open stream:
No such file or directory in /home/hletf/public_html/essex/index.php on line 27
Is your problem already stated there? There is an error since include(txt) is NOT a right inclusion of a file. Create your *.txt file first and then include it. Something like include("foo.txt")
If you want files .txt to be parse as .php files you should change your apache configuration, or write your own class which will parse this file and return value that you need
Related
I need to connect my mamp-Database with the craftcms files, in order to create a new website.
I put all the files for the installation of craft in the requested files. As I wanted to open the link for creating the new page, i got the error message:
The file structure you can see in the images below.
how do I change the file path correctly? Or how do I change the file structure, so the host will find it?
Thanks very much for you answer in advance
I don't know how to fix this but the problem is that it won't upload to the server that I'm using to host the website it creates the folder just fine but won't move it. The coding for the moving is below.
This is the error I get
Warning: move_uploaded_file(./userdata/profile_pics/iOy1pQXTZsLw7VA/) [function.move-uploaded-file]: failed to open stream: Is a directory in /home/a4640336/public_html/account_settings.php on line 103
and as well as this error code
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpX1zVno' to './userdata/profile_pics/iOy1pQXTZsLw7VA/' in /home/a4640336/public_html/account_settings.php on line 103
move_uploaded_file(#$_FILES["profilepic"]["tmp_name"],"./userdata/profile_pics/$rand_dir_name/".$FILES["profilepic"]["name"]);
echo "Your profile pic has been updated!".#$_FILES ["profilepic"]["name"];
//$profile_pic_name = #$_FILES["profilepic"] ["name"];
//$profile_pic_query= mysql_query("UPDATE users SET profile_pic='$rand_dir_name/$profile_pic_name' WHERE username='$username'");
//header("location: account_settings.php");
Overall I have tried to change where it is located to have it leading directly from the source but it doesn't change. If anyone can help please help me!
PS the commented out parts were done to be able to see the error
For those using PHP on Windows and IIS, you SHOULD set the "upload_tmp_dir" value in php.ini to some directory around where your websites directory is, create that directory, and then set the same permissions on it that you have set for your websites directory. Otherwise, when you upload a file and it goes into C:\WINDOWS\Temp, then you move it to your website directory, its permissions will NOT be set correctly.And If you try to upload a file larger than the post_max_size value (or multi files), the page will only refresh itself and no errors are thrown.
The destination directory must exist; move_uploaded_file() will not automatically create it for you.
You must
make sure that the file is not empty.
make sure the file name in English characters, numbers and (_-.) symbols, For more protection.
make sure that the file name not bigger than 250 characters.
Check File extensions and Mime Types that you want to allow in your
project. You can use : pathinfo(). or you can use regular expression for check File extensions as in example
Check file size and make sure the limit of php.ini to upload files
is what you want, You can start from here.
Check the file content if have a bad codes or something like this
function
move_uploaded_file($_FILES["file"]["tmp_name"], "../uploads/" . $_FILES["file"]["name"]);
Also check dir have writable permission
you need to use server path for file upload
$files = glob($_SERVER["DOCUMENT_ROOT"]."/myFolder/*");
$_SERVER["DOCUMENT_ROOT"] will get server path like var/host/public_html/your_folder
May this help you
I have a line of code that is supposed to copy image from one directory to another:
copy("http://localhost:8080/wordpress/wp-content/uploads/2015/06/uploaded_background.jpg","http://localhost:8080/wordpress/wp-content/themes/landing-page/img/desktop-background.jpg");
This is located in wordpress theme header.php file, however I am receiving an error message:
Warning:
copy(http://localhost:8080/wordpress/wp-content/themes/landing-page/img/desktop-background.jpg):
failed to open stream: HTTP wrapper does not support writeable
connections in
C:\wamp\www\wordpress\wp-content\themes\landing-page\header.php on
line 42
Line 42 is where my copy function line is located.
How can I solve this issue. Any suggestions or links would help a lot.
instead of using
copy("http://localhost:8080/wordpress/wp-content/uploads/2015/06/uploaded_background.jpg","http://localhost:8080/wordpress/wp-content/themes/landing-page/img/desktop-background.jpg");
try
copy`("/yourserverfolderpath/wordpress/wp-content/uploads/2015/06/uploaded_background.jpg","/yourserverfolderpath//wordpress/wp-content/themes/landing-page/img/desktop-background.jpg");`
yourserverfolderpath/ could be something like /home/user/abc/
see you ftp or cpanel for exact path
see this SO question as guideline
PS:
In case of local file, path would be something like D:\php\www\www\xml.php
as pointed by #dlegall in comments and as per documentation, First param of copy() can be a valid URL, see the docs here
You should use a local path as a 2nd parameter to copy(), since http protocol does not support file overwriting.
The destination path. If dest is a URL, the copy operation may fail if the wrapper does not support overwriting of existing files.
Source : http://php.net/manual/en/function.copy.php
I'm trying to open a .p12 key file I placed in the same directory as functions.php. I tried using file_get_contents() to open the file, I also tried opening other random files and found that I could not.
PHP Warning: fopen(key.p12) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in path/wp-content/themes/theme-name/functions.php on line 26
I've been trying to get around this for hours.
Doesn't matter that functions.php and key.p12 are in the same directory. It all matters what the running script's working directory is. e.g.
/maindir/subdir/functions.php
file_get_contents('key.p12');
/maindir/script.php
include('subdir/functions.php');
In this case, the working directory will be maindir, and f_g_c() will be doing the equivalent of file_get_contents('/maindir/key.p12'), and fail, because the file is NOT in maindir.
Check getcwd() at the point you're doing the file_get_contents() call, and check what the working directory really is at that point. You'll probably find it's something completely different than the dir that functions.php lives in.
I'm going through the O'Reilly book Learning PHP & MySQL 2nd ed. by Michele Davis & Jon Phillips.
I'm stuck on example 11-28. The goal is to upload a picture and move it from /tmp to an uploads folder if it meets certain conditions: file size, type, and whether or not it was uploaded. This is being stored on my home Ubuntu server.
The form is here, and the code is here. Having a hard time getting it to show up.
When I hit the submit button w/o there being a file in the file box, I get the following warning:
Warning: unlink() [function.unlink]: No such file or directory in /home/luna/public_html/learn_php/up_urs.php on line 10
When I submit a file bigger than maxsize I get my error message:
Error. File must be less than 28480 bytes.
When I submit a file of the wrong type I get my error message:
You may only upload .gif & .jpg files.
When I submit a file that's the right type & size I get the following warning and my OK message:
Warning: move_uploaded_file(learn_php/uploads/) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/luna/public_html/learn_php/up_urs.php on line 21
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php4Mhykl' to 'learn_php/uploads/' in /home/luna/public_html/learn_php/up_urs.php on line 21
Thanks for your upload.
What I've tried:
I thought the problem was permissions but changing the directory learn_php to 777 made no difference so I changed it back to 755.
Changing the path from "uploads" to /home/luna/public_html/learn_php/uploads
Using getcwd() before & after the unlink & move_uploaded_file commands but that only told me I was in learn_php...
I tried uncommenting //print_r($_FILES); but that didn't show me anything after pressing submit.
Not sure what to look for now. Thanks for any help :)
The first error you see is because you are trying to unlink a file that doesn't exist on line 10. After you do the is_uploaded_file() check you should do a quick if ( isset($_FILES['upload_file']['tmp_name']) ) before doing the unlink.
The last two warnings are because it seems you don't have the upload directory already created. I don't think move_uploaded_file() will create it for you. So just create that directory and make sure that it has proper permissions to be written to.
As a beginner, I would also recommend checking the return values of these functions so that you don't return 'all good' when things have actually failed for some reason. Start putting in code like if ( !move_uploaded_file($_FILES['upload_file']['tmp_name'], "/path/to/learn_php/uploads/".$_files['upload_file']['name']) ) { $error = "Could not move the file to the uploads directory."; } else { print "All good, thanks for the upload."; exit(); }
See my answer here. That will give you a function to find the current root directory, which you can use as a prefix for file uploads and image manipulation.
Then, before running unlink, do an is_file() check first (and before moving it, you could run it to to ensure it exists in tmp if you are paranoid)
Rather than guessing your code path try working down from the top.
$uploadpath=$_SERVER['DOCUMENT_ROOT'].'\learn_php\uploads\';
I might be wrong, since you didnt post your source, but you are missing a slash in front of a directory, so it may be trying to store it in \learn_php\learn_php\uploads\ which wont exist, since the PHP file is already in that directory, so it is attempting to access a sub directory.
if all else fails, you will probably want to brush up on the docs.
http://php.net/manual/en/features.file-upload.php
Warning: move_uploaded_file()
[function.move-uploaded-file]: Unable
to move '/tmp/php4Mhykl' to
'learn_php/uploads/' in
/home/luna/public_html/learn_php/up_urs.php
on line 21
This is telling you that the folder you are trying to move to (learn_php/uploads/) doesn't exist. Double check that you've created that folder on your server.