FancyUpload to different folders - php

I got a plugin online(fancyupload), trying to upload multiple file to different folders. first I created the folders using mkdir() then passed the folder name to a session id both in the index.php file as well as the script.php file, but I discovered the script.php file doesn't see the session and it uploads the files directly to the uploadedfiles folder. can anyone help as I have tried everything possible. I am new to stackoverflow( although been reading on issues here for a while) so really don't know the rules here.
Thank you in advance
index.php
<?php
session_start();
mkdir("C:/softwares/wamp/www/Emma/uploadedfiles/".$_POST['directory']."/");
$_SESSION['directory'] = $_POST['directory'];
Script.php
move_uploaded_file($_FILES['photoupload']['tmp_name'], "uploadedfiles/".$_SESSION['directory']."/".$_FILES['photoupload']['name']);
chmod("uploadedfiles/".$_SESSION['directory']."/".$_FILES['photoupload']['name'], 0777);

Sorry for the question, I have solved the problem, it was quite easy was just thinking in one direction!!! Thanks anyways viewers

Related

Create folder outside public_html to upload files

I creating script and I need to let users upload files (images) . and for security reasons I want to make file folder outside public_html.
But my problem is maybe my potential customers may have different folders structure in their servers.
So my question is : There is a way in php to go back one folder before public_html ?
Another possible case if my client put script file in directory like that public_html/demo/ , so in that case I need to go 2 folders back.
I try to use $_SERVER["DOCUMENT_ROOT"] but it give the public server directory.
any help or suggestion will be helpfull. thank you
If the php user has the permission to do so, you should be able to include/write files to a directory using a relative path for example:
include("../test.php");
Likewise if you had a directory which was writable by the php user you should be able to create files in that directory also using a relative path:
$ cat test1.php
<?php
$file = fopen("../test.php", "w");
fwrite($file, "Hello World. Testing!\n");
fclose($file);
include("../test.php");
$ php test1.php
Hello World. Testing!

Scandir For Directories Above

have a website that is obviously in the root of my server. I am now making a web app, which lies in m/iphone/. All was going well but my website uses scandir() with all of the files in a folder on the root of my server.
How can I access these files from when I'm inside the m/iphone directory?
Sorry if it's a really obvious answer, I'm a complete beginner.
Thanks in advance for any help
You have to use .. which stands for back in terms of folders, in your case you should run something like this:
scandir(dirname(__DIR__));
You should play with .. in path name:
scandir(dirname(__FILE__).'../anotherfolder'); //go back one folder and go to folder 'anotherfolder'
Hope it helps.

PHP, MoDX: Upload file from custom PHP Snippet

I have a snippet that I want to use to upload a file.
The script seems to be running fine until it gets to the point where PHP transfers the file from temp docs to my own folder.
My folder is called 'uploads' and is the root.
On ModX the PHP files directory is
/core/cache/includes/elements/modsnippet
I cannot seem to figure out a way to direct the script to send the file back from the modsnippet directory to the public_html/uploads directory.
So far I have tried:
move_uploaded_file($_FILES['instlogo']['tmp_name'], dirname(__FILE__) . "/../../../../uploads".$new_file_name)
;
as well as absolute paths, eg:
http://mysite.com/uploads
To no avail.
Would anyone know a way of doing this correctly? Thanks!
(ps: permissions on that folder are 777)
can you try something like:
$my_uploads = $modx->getOption('base_path').'uploads/';
move_uploaded_file($_FILES['instlogo']['tmp_name'], $my_uploads.$new_file_name)
the base_path option will give you the full file system path [from the server root]
if not & you are getting a filesystem error, the server logs [aapche] should be telling you why. Do you have access to them?

php : Cannot reference current's file parent's folder subdirectory!

Please help!
My directory structure is this:
my_application
my_application/index.php
my_application/images
my_application/phpcode/my_script.php
I have this code in my_script.php
<?php
if(file_exists('../images)){
// do something
}
?>
It works in wamp perfectly!!!
But when I upload it to my server (hostgator), it doesn't work.
In my server I do not upload it to root folder, but to a subfolder.
rootfolder/folder1/folder2/my_application
From what I understand, .. is in reference to the root path, not the current file.
How can I reference the current's file parent's folder images?
Sorry for my English. Please help! I'm stuck on this one.
You can simpli use dirname($SCRIPT_FILENAME) to reference the direcotry of your current script.
Have a look at PHP Constant and PHP Reserved Variable :)
Hope this help

Location of a directory created with mkdir in PHP

I've been trying a bunch of stuff with creating zips and files and whatnot with php, and it's safe to say I messed up quite a few times...
My most recent:
$tmpp = tempnam('../test','mod');
echo "<br/>"."<br/>".basename($tmpp).'<br/>'."<br/>".$tmpp.'<br/>'."<br/>";
echo mkdir(basename('../test/'.$tmpp));
I meant to do
$tmpp = tempnam('../test','mod');
echo "<br/>"."<br/>".basename($tmpp).'<br/>'."<br/>".$tmpp.'<br/>'."<br/>";
echo mkdir('../test/'.basename($tmpp));
Oh well though, mistake is made. Where is this just created directory? How can I see all the other files and directories and things as well as the tmp folder?
edit: long story short: I've created a bunch of files and directories that I can't account for and I want to be able to find them on clean then off my server. How can I view ALL the files on my server, including in the tmp folder?
What's the return value of mkdir? "false" ?
If so, I think maybe you need check your write permisson of the account which execute this php script.

Categories