almystersv Posted February 19, 2008 Share Posted February 19, 2008 Hi Guys, Im using this AJAX code i have found on the internet to use as a method of file sharing. <?php // Edit upload location here $destination_path = getcwd().DIRECTORY_SEPARATOR; $result = 0; $target_path = $destination_path . basename( $_FILES['myfile']['name']); if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) { $result = 1; } sleep(1); ?> <script language="javascript" type="text/javascript">window.top.window.stopUpload(<?php echo $result; ?>);</script> <?php session_start(); if (isset($_SESSION['username']) == false){ header("Location: login.php"); exit(); } require "connect.php"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>BIS Portal File Uploader</title> <link rel="stylesheet" type="text/css" href="mystylelogin.css" /> <script language="javascript" type="text/javascript"> <!-- function startUpload(){ document.getElementById('f1_upload_process').style.visibility = 'visible'; document.getElementById('f1_upload_form').style.visibility = 'hidden'; return true; } function stopUpload(success){ var result = ''; if (success == 1){ result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>'; } else { result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>'; } document.getElementById('f1_upload_process').style.visibility = 'hidden'; document.getElementById('f1_upload_form').innerHTML = result + '<label>File: <input name="myfile" type="file" size="30" /><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>'; document.getElementById('f1_upload_form').style.visibility = 'visible'; return true; } //--> </script> </head> <body> <?php include ("header.php"); ?> <form action="upload.php" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="startUpload();" > <p id="f1_upload_process">Loading...<br/><img src="images/loader.gif" /><br/></p> <p id="f1_upload_form" align="center"><br/> <label>File: <input name="myfile" type="file" size="30" /></label> <label> <input type="submit" name="submitBtn" class="sbtn" value="Upload" /></label> </p> <iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe> </form> </body> </html> Is it possible to display a table below the uploader of the documents in that directory so as if to show all the files that have been uploaded. Possibly creating links to all of them!? Also how would i go about changing the code so the user can select where they wish to upload the file too rather than it uploading to the current working directory. Thanks Quote Link to comment Share on other sites More sharing options...
priti Posted February 20, 2008 Share Posted February 20, 2008 Hi, If not wrong then you suppose not to allow your user to upload files anywhere on your server.Hence you would be having specific directory where user can upload their files. Simply set $target_path=path/to/main/directory. on user side list already existing directory this can be done by making ajax request to list the directory in the main directory.The user is having the option to select any of the one hence thru form you can send the $target_path and upload your temp files to $target_path. this tweak will be done in both php and html file . For showing the uploaded document you can do it also.Simply when the file is moved check if file_exists($newly_uploaded_file) on server and show that in html form. Regards Regards Quote Link to comment Share on other sites More sharing options...
almystersv Posted February 20, 2008 Author Share Posted February 20, 2008 sorry, any chance of showing me some example code as you have lost me there. I am fairly new to php and have only picked it up since after christmas. Thanks for taking a look and your time. Quote Link to comment Share on other sites More sharing options...
priti Posted February 21, 2008 Share Posted February 21, 2008 i don't have any dummy example which match your requirement as you already have the file upload script with you then you can start going step by step. i will suggest first: write a php function to list the directories inmain directory create a directory on server called 'userUploads' chmid 777 and create some subdirectory in this like userUploads -flowers -trees -plants (sub directory is your choice) now write a php script to fetch userUpload and try ot list these sub directory.Once you are thru with this then create a ajax request to call that function and output them on your html form. finish this much and let me know if you get stuck in somewhere while doing this. Regards Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.