School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,579 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,242 people online right now. Registration is fast and FREE... Join Now!




Javascript Auto Upload

 

Javascript Auto Upload, Following on...

Chalie9809

18 Jun, 2009 - 02:45 AM
Post #1

New D.I.C Head
*

Joined: 28 Jan, 2009
Posts: 37



Thanked: 4 times
My Contributions
Following on from my post here: Php Auto Upload I have been told that an "Auto" upload is not possible in php, but can be done with javascript. Im wondering If anyone can give me some help on this as I am not well aquainted with javascript, heres what I have (the php):

index.php
CODE
<html>
<head>
<title>Upload</title>
<meta name="author" content="Charlie Sheather" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<!--[if IE]><link href="css/IE.css" rel="stylesheet" type="text/css" /><![endif]-->
</head>
<body onload="document.forms['uploadFile'].submit();">
<div class="boxLoadMessage">
    <center>
        <h2>.: Fuller Fresh Upload Form :.</h2>
        <h3>Multiple Files Upload.</h3>
        <form action="multiple_upload_ac.php" method="post" enctype="multipart/form-data" id="uploadFile" class="uploadFile" name="uploadFile">
            <input name="ufile[]" type="file" id="ufile[]" size="50" value="P:/test1.xls"/><br />
            <input name="ufile[]" type="file" id="ufile[]" size="50" value="P:/test2.pdf"/><br />
            <br />
            <input type="submit" name="submit" id="submit" value="Submit" />
        </form>
</div>
</body>
</html>


multiple_upload_ac.php
CODE
<?php
//set where you want to store files
//in this example we keep file in folder upload
//$_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif

$path1= "upload/".$_FILES['ufile']['name'][0];
$path2= "upload/".$_FILES['ufile']['name'][1];

//copy file to where you want to store file
copy($_FILES['ufile']['tmp_name'][0], $path1);
copy($_FILES['ufile']['tmp_name'][1], $path2);

//$_FILES['ufile']['name'] = file name
//$_FILES['ufile']['size'] = file size
//$_FILES['ufile']['type'] = type of file
echo "File Name :".$_FILES['ufile']['name'][0]."<BR/>";
echo "File Size :".$_FILES['ufile']['size'][0]."<BR/>";
echo "File Type :".$_FILES['ufile']['type'][0]."<BR/>";
echo "<P>";

echo "File Name :".$_FILES['ufile']['name'][1]."<BR/>";
echo "File Size :".$_FILES['ufile']['size'][1]."<BR/>";
echo "File Type :".$_FILES['ufile']['type'][1]."<BR/>";
echo "<P>";

///////////////////////////////////////////////////////

// Use this code to display the error or success.

$filesize1=$_FILES['ufile']['size'][0];
$filesize2=$_FILES['ufile']['size'][1];

if($filesize1 && $filesize2 != 0)
{
echo "We have recieved your files";
}

else {
echo "ERROR.....";
}

//////////////////////////////////////////////

// What files that have a problem? (if found)

if($filesize1==0) {
echo "There're something error in your first file";
echo "<BR />";
}

if($filesize2==0) {
echo "There're something error in your second file";
echo "<BR />";
}

?>



I would like to have it so you cant change the specified file.


Cheers

Charlie

User is offlineProfile CardPM
+Quote Post


girasquid

RE: Javascript Auto Upload

18 Jun, 2009 - 07:40 AM
Post #2

Barbarbar
Group Icon

Joined: 3 Oct, 2006
Posts: 1,628



Thanked: 53 times
Dream Kudos: 825
My Contributions
I'm afraid that the 'auto upload' you are looking for here(where a specific file from the user's system is uploaded) can't be built with javascript either.

Allowing your system to force users to upload a specific file from their computer would be a huge security hole - while your intentions may be good, what's to prevent a bad apple from writing something that makes you upload C:\some\sensitive\file?
User is offlineProfile CardPM
+Quote Post

BetaWar

RE: Javascript Auto Upload

18 Jun, 2009 - 08:46 AM
Post #3

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 4,729



Thanked: 269 times
Dream Kudos: 1400
My Contributions
QUOTE
Allowing your system to force users to upload a specific file from their computer would be a huge security hole - while your intentions may be good, what's to prevent a bad apple from writing something that makes you upload C:\some\sensitive\file?

Move importantly (at least to you, probably), what is to stop the users from finding out what files is uploaded and then create a hacked version of that file which will wipe your site clean? It can be done fairly easily.

Now, in theory all you have to do is put a file destination in a file input box and submit the form, but that requires the user actually has that file on their computer.
User is offlineProfile CardPM
+Quote Post

Chalie9809

RE: Javascript Auto Upload

19 Jun, 2009 - 12:17 AM
Post #4

New D.I.C Head
*

Joined: 28 Jan, 2009
Posts: 37



Thanked: 4 times
My Contributions
Thankyou both for your input but why does everyone think this is some huge security issue, its on a secure site, will at least one login required to get to and im using it to update a file that needs to be done about 3-4 times a day. Also if someone wanted to use it to upload files from another's computer, why wouldn't they make there own? Could someone at least give me some idea on how to?

Charlie
User is offlineProfile CardPM
+Quote Post

moopet

RE: Javascript Auto Upload

19 Jun, 2009 - 01:53 AM
Post #5

D.I.C Regular
***

Joined: 2 Apr, 2009
Posts: 342



Thanked: 32 times
My Contributions
QUOTE(Chalie9809 @ 19 Jun, 2009 - 07:17 AM) *

Thankyou both for your input but why does everyone think this is some huge security issue, its on a secure site, will at least one login required to get to and im using it to update a file that needs to be done about 3-4 times a day. Also if someone wanted to use it to upload files from another's computer, why wouldn't they make there own? Could someone at least give me some idea on how to?

Charlie


No, you can't do it. It's conceivable some idiotic company might bring out a browser that lets you do it in the future, but I'd hope not.
It's simple: if there was a way to automatically take a file from someone's computer and put it on your server, you could steal anything from them you want. How about their browser password list, for example. It's difficult to imagine how you can't see this is a security issue.
You know all the security bugs that are found every day in modern browsers? The biggie, the worst-case, is that you can read or write to the user's filesystem. If that happens, a patch for the browser is brought out ASAP by throwing more and more monkeys at the problem until the company is less terrified of the bad press.
User is offlineProfile CardPM
+Quote Post

Chalie9809

RE: Javascript Auto Upload

19 Jun, 2009 - 03:53 PM
Post #6

New D.I.C Head
*

Joined: 28 Jan, 2009
Posts: 37



Thanked: 4 times
My Contributions
Ok. Thankyou all for your contribution, I understand now why it cant be done (the way I suggested)
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 08:25AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month