file upload
Posted: Mon Sep 13, 2010 8:11 am
Hi guys, i'm working on a site that has an online application, with the application i am adding an upload feature so they can upload and documents that we will need to see. After looking online i have found a script to do this, but i need to edit it slightly, i can edit smaller parts no problem, but i'm a little confused with other parts.
here are the 3 files that i have so farI have made a few changes to what i had found online, but i now need to make it so that,
1. you may only upload images(scanned documents) or document files(although anything scanned wont come as a document file would it?)
2.the file name can be changed (have done this partially as you can see with the session) so that the saved file will be $_SESSION[appid]-doc1.blah even though the file uploaded was named scan50.blah, i managed this but lost the extension meaning the saved file was just $_SESSION[appid]-doc1 (if this makes sence to you)
3. i would like there to be an add upload button so that you dont say at begining how many files u will upload, using document.write i imagine, but when i used this in the past i lost the rest of the page :S
anything you can help me with here would be greatfully appreciated.
Thanks
here are the 3 files that i have so far
Code: Select all
//upload.php
<?php
session_start();
$_SESSION['appid']="leo123";
?>
<html>
<HEAD>
<title>Choose Number of Files to Upload</title>
</head>
<body>
<form name="form1" method="post" action="uploadForm.php">
<p>How many files would you like to upload? (Max = 9).</p>
<p>
<input name="uploadsNeeded" type="text" id="uploadsNeeded" maxlength="1" />
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>Code: Select all
//uploadForm.php
<?php
session_start();
?>
<html>
<title>Upload files</title>
</head>
<body>
<form name="form1" enctype="multipart/form-data" method="post" action="uploadFiles.php">
<p>
<?
$uploadsNeeded = $_POST['uploadsNeeded'];
for($i=0; $i < $uploadsNeeded; $i++){
?>
<input name="uploadFile<? echo $i;?>" type="file" id="uploadFile<? echo $i;?>" />
</p>
<? } ?>
<p><input name="uploadsNeeded" type="hidden" value="<? echo $uploadsNeeded;?>" />
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>Code: Select all
//uploadFiles.php
<?
session_start();
$uploadsNeeded = $_POST['uploadsNeeded'];
for($i = 0; $i < $uploadsNeeded; $i++){
$file_name = $_FILES['uploadFile'. $i]['name'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$file_name = $_SESSION[appid]."-"."$file_name";
$copy = copy($_FILES['uploadFile'. $i]['tmp_name'],"uploaded/". $file_name);
// prompt if successfully copied
if($copy){
echo "$file_name | uploaded sucessfully!<br>";
}else{
echo "$file_name | could not be uploaded!<br>";
}
}
?>1. you may only upload images(scanned documents) or document files(although anything scanned wont come as a document file would it?)
2.the file name can be changed (have done this partially as you can see with the session) so that the saved file will be $_SESSION[appid]-doc1.blah even though the file uploaded was named scan50.blah, i managed this but lost the extension meaning the saved file was just $_SESSION[appid]-doc1 (if this makes sence to you)
3. i would like there to be an add upload button so that you dont say at begining how many files u will upload, using document.write i imagine, but when i used this in the past i lost the rest of the page :S
anything you can help me with here would be greatfully appreciated.
Thanks