I have a form where users can upload images. I know how to do it with HTML/PHP and I know that I have to move the temp file to the permanent directory. Well this all works well when my file that processes the form, is in the root directory. But, I would like to have it work within another directory, on the same server.
The Structure is this:
ROOT
>images
>mobile
>upload.php
I would like to have the file put inside images, which is outside of the "mobile" directory.
My current upload path that does not work is:
define('UPLOADPATH', 'images/');
So essentially I need to go back one directory and then into images. How can I do this?
You need to add a .. To move to the parent directory. See this resource for more information
Related
I want to set my wordpress files to upload to /home/public_html/images instead of /wp_content/uploads, I have gotten to the point that it gives me the correct url for /home/public_html/images but I have to move the new files from /wp_content/uploads to /home/public_html/images for it to work
I have tried changing the upload path in wp-options.php but that just makes a subdirectory in my sites folder called public_html and puts the image there instead of actually putting it in /home/public_html/images
Try going to the wp_config.php file and adding this line of code:
define('UPLOADS', 'images');
This should put the images in a folder under /public_html instead of the typical /wp_content folder.
https://developer.wordpress.org/apis/wp-config-php/#moving-uploads-folder
I have one root folder called GASS where I put all my php files and other related folders (templates,images,js,fonts,css)inside. When i try to run my project in localhost, http://localhost/GASS/alarm_A16GSM.php everything went smoothly. I wanted to change the URL to be more specific, http://localhost/GASS/alarmsystem/16zone/A16/overview.php thus i rename the php file and put it inside folders.
GASS
alarm-system
16-zone
A16
overview
However when i try to run the new URL,the page shows error.This is the error message:
Warning: include(templates/header.php): failed to open stream: No such file or directory in .....
Code for the first URL where the page load successfully.
<div class="overview"><a href="alarm_A16GSM.php" id="overview-selected"><span>
Code for the new URL where the page shows error.
<a href="alarm-system/16-zone/A16/overview.php" id="overview-selected">
It seems like i need to configure something which i do not know what it is.
How am i going to load the page successfully using the new URL? How am i going to traverse four levels up to the root directory so that the page load successfully? Why i cannot directly call the php file using the(alarm-system/16-zone/A16/overview.php) path?
p/s: sorry for my bad English.
It looks like there is a line in your Php file, probably like
include 'templates/header.php';
Include can't find the file using that relative path, because you moved the calling file.
Probably you could change that to
include '../../../../templates/header.php';
To get back down to the GASS folder that apparently has a folder called 'templates' with a file 'header.php' that is required.
An absolute path would be good, instead but it refers to the filesystem path, not webserver path - so you'd need to know your web root folder name on the server.
Copying all the folders (templates,images,js,fonts,css) to the folder overview will solve the issue. Now there is no template file on the folder 'overview' so header.php is failed to load. Another option is create a file save all the included file path and call this file.
I have a simple php image upload form that saves the images in a temporary folder, lets call it temp, and when the image is approved by me I manually copy it to the album folder.
My question is, if there is a way for someone or I don't know, a search engine maybe to find "guess" my temp folder and what images are inside ( before approve ).
You wrote it yourself:
The temp is inside public_html
Doesn't that answer your question?
If this is not desirable, create a .htaccess file inside the temp folder, with this content:
Deny from all
It depends on the location of the temp folder. If the folder lies outside the root directory of your server its not discoverable but if it lies inside the root directory it is discoverable. However you can limit the access to your temp folder if its inside the root of the server through htaccess. Or you can place a index.php file inside the folder with a header redirect so that no one can see the file(image) list.
I have a problem on linking files such as stylesheets, images, database connection file(db.php), script files and etc.. because they are located outside the file where they are included/linked.
For example assuming this is the location of the main file where everything will be called:
my website directory/admin/thefilewhereeverythingwillbecalled.php
in thefilewhereeverythingwillbecalled.php, I must call the db.php which is located outside the folder that contains thefilewhereeverythingwillbecalled.php
e.g. my website directory/-this is the directory where the db.php is located-/thefilewhereeverythingwillbecalled.php - ditto the style sheets and script.
However the stylesheets and script are in the folder cssandjs (contains all stylesheets and script files) which this folder are located before the location of the thefilewhereeverythingwillbecalled.php
e.g. my website directory/-here is where the cssandjs folder is located-/thefilewhereeverythingwillbecalled.php
Generally I'm just having a problem on linking files which is outside from the file where it called those files. Can someone give me an idea how to link it please?
I tried this:
../cssandjs/style.cssand ./cssandjs/jquery.js but none of them work
If I'm correct, it's 2 directories up. Try this :
../../cssandjs/style.css
This will work if /cssandjs/ is in your website directory.
You should be a bit more specific with your directory names instead of -here is where this is located-
Can't seem to figure out which are in the same folder.
try to include full path to the files.
Try referencing the files like including the directories and files with
$_SERVER['DOCUMENT_ROOT']."/dirName/file.ext";
or use relative paths "../dirnName/file.ext";
first method is preferred
i have my web folder in c:/wamp/www/ which is the default webroot for wamp. Then i have a folder image in c:/image/ that contains images been processed by another application which i wont like to relocate. I want to be able to load up an image with its file name from c:/image/
e.g. img src = "c:/image/FA12.jpg"
within my PHP scripts. I really Need Help on this Please. Thanks for your support.
If you need to read a file into php use "c:\image\FA12.jpg". You may also create a link "file://c\image\FA12.jpg". There's no way to create a relative path, since it is outside root dir.
As per my knowledge it is better to create a folder of your images under your localhost or server ('var/www/images') to have a proper relative URL to that images.
Url's like c:\image\fa12.jpg can create problems when you make your product online. Other wise you can do provide static urls as kirilloid suggest or you can copy that images to some proper folder in your localhost sever with use of php function "copy" and use that folder as a reference. avoid static url's if possible.:)
as i have linux system now i tested below code locally. create one file test.php under /www and put below code in it and run file in browser. see if this can be your solution
<?php $link = $_SERVER['DOCUMENT_ROOT'];
$domain = strstr($link, '/www');
echo $domain;//this will output /www
$root = strstr($link, '/www', true);
echo "<br>".$root;//this will output /var
?>
You can try this by putting "/wamp/www" instead of "/www" in above code and you will get c:/ (perhaps) in $root and then appeng folder name images and path accordingly to $root.
May this will help you