Uploading multiple files @ once..?
Moderators: egami, macek, gesf
Hi there,
I am working on a website which has league tables. As a temporary measure (until I get the MySQL db sorted) I have set up a CSV parser script (with the kind help of topic http://www.php-forum.com/p/viewtopic.php?t=572).
However, the guy whom is supposed to be updating it is a very computer illiterate and is having trouble uploading the 8 files to the site. I have been searching for an easily customisable script which will upload the files and place them in the appropriate directory (ensuring they are all in lowercase).
Any help would be VERY appreciated, thank you... :wink:
atw
I am working on a website which has league tables. As a temporary measure (until I get the MySQL db sorted) I have set up a CSV parser script (with the kind help of topic http://www.php-forum.com/p/viewtopic.php?t=572).
However, the guy whom is supposed to be updating it is a very computer illiterate and is having trouble uploading the 8 files to the site. I have been searching for an easily customisable script which will upload the files and place them in the appropriate directory (ensuring they are all in lowercase).
Any help would be VERY appreciated, thank you... :wink:
atw
I have a php script that does something like that...
I found it some time ago and I don't know who made it and where to download it. If anybody knows tell me.
I would like to get some expert feadback on it before you use it... Maybe the moderator (Pejone) would give us a comment?!
Do you want me to publish the code?
(I would like to get an OK from the moderator (Pejone) to)
;]-
I found it some time ago and I don't know who made it and where to download it. If anybody knows tell me.
I would like to get some expert feadback on it before you use it... Maybe the moderator (Pejone) would give us a comment?!
Do you want me to publish the code?
(I would like to get an OK from the moderator (Pejone) to)
;]-
It's not mine... and I dont know whos it is...
Html:
<html>
<head>
<title>Upload Image</title>
</head>
<body>
<form method=POST action=do_upload.php enctype=multipart/form-data>
<p>Files to upload:<br>
<input type=file name=img1 size=30><br>
<input type=file name=img2 size=30><br>
<input type=file name=img3 size=30><br>
<input type=file name=img4 size=30><br>
<input type=file name=img5 size=30><br>
<input type="submit" name="submit" value="Upload">
</form>
</body>
</html>
I think you can just add several <input type=file name=img* size=30><br> with new number for eac up to 8... But then you have to do the same in the code...
do_upload.php:
I repeat! It's not mine! If anybody knows hos it is.. I would like 2 know.
I would allso like to get a critical eye at the code.. somethings doesent sem totally right here.... I think it could be done easier.
Try it.. I think i worcks just the way it is. ;]-
Html:
<html>
<head>
<title>Upload Image</title>
</head>
<body>
<form method=POST action=do_upload.php enctype=multipart/form-data>
<p>Files to upload:<br>
<input type=file name=img1 size=30><br>
<input type=file name=img2 size=30><br>
<input type=file name=img3 size=30><br>
<input type=file name=img4 size=30><br>
<input type=file name=img5 size=30><br>
<input type="submit" name="submit" value="Upload">
</form>
</body>
</html>
I think you can just add several <input type=file name=img* size=30><br> with new number for eac up to 8... But then you have to do the same in the code...
do_upload.php:
Code: Select all
<?
//user defined variables
$abpath = "/home/site/www.domene.no/uplader/img"; //Absolute path to where images are uploaded. No trailing slash
$sizelim = "yes"; //Do you want size limit, yes or no
$size = "2500000"; //What do you want size limited to be if there is one
//all image types to upload
$cert1 = "image/pjpeg"; //Jpeg type 1
$cert2 = "image/jpeg"; //Jpeg type 2
$cert3 = "image/gif"; //Gif type
$cert4 = "image/ief"; //Ief type
$cert5 = "image/png"; //Png type
$cert6 = "image/tiff"; //Tiff type
$cert7 = "image/bmp"; //Bmp Type
$cert8 = "image/vnd.wap.wbmp"; //Wbmp type
$cert9 = "image/x-cmu-raster"; //Ras type
$cert10 = "image/x-x-portable-anymap"; //Pnm type
$cert11 = "image/x-portable-bitmap"; //Pbm type
$cert12 = "image/x-portable-graymap"; //Pgm type
$cert13 = "image/x-portable-pixmap"; //Ppm type
$cert14 = "image/x-rgb"; //Rgb type
$cert15 = "image/x-xbitmap"; //Xbm type
$cert16 = "image/x-xpixmap"; //Xpm type
$cert17 = "image/x-xwindowdump"; //Xwd type
$log = "";
//begin upload 1
//checks if file exists
if ($img1_name == "") {
$log .= "No file selected for upload 1<br>";
}
if ($img1_name != "") {
//checks if file exists
if (file_exists("$abpath/$img1_name")) {
$log .= "File 1 already existed<br>";
} else {
//checks if files to big
if (($sizelim == "yes") && ($img1_size > $size)) {
$log .= "File 1 was too big<br>";
} else {
//Checks if file is an image
if (($img1_type == $cert1) or ($img1_type == $cert2) or ($img1_type == $cert3) or ($img1_type == $cert4) or ($img1_type == $cert5) or ($img1_type == $cert6) or ($img1_type == $cert7) or ($img1_type == $cert8) or ($img1_type == $cert9) or ($img1_type == $cert10) or ($img1_type == $cert11) or ($img1_type == $cert12) or ($img1_type == $cert13) or ($img1_type == $cert14) or ($img1_type == $cert15) or ($img1_type == $cert16) or ($img1_type == $cert17)) {
@copy($img1, "$abpath/$img1_name") or $log .= "Couldn't copy image 1 to server<br>";
if (file_exists("$abpath/$img1_name")) {
$log .= "File 1 was uploaded<br>";
}
} else {
$log .= "File 1 is not an image<br>";
}
}
}
}
//Upload #2
//checks if file exists
if ($img2_name == "") {
$log .= "No file selected for upload 2<br>";
}
if ($img2_name != "") {
//checks if file exists
if (file_exists("$abpath/$img2_name")) {
$log .= "File 2 already existed<br>";
} else {
//checks if files to big
if (($sizelim == "yes") && ($img2_size > $size)) {
$log .= "File 2 was too big<br>";
} else {
//Checks if file is an image
if (($img2_type == $cert1) or ($img2_type == $cert2) or ($img2_type == $cert3) or ($img2_type == $cert4) or ($img2_type == $cert5) or ($img2_type == $cert6) or ($img2_type == $cert7) or ($img2_type == $cert8) or ($img2_type == $cert9) or ($img2_type == $cert10) or ($img2_type == $cert11) or ($img2_type == $cert12) or ($img2_type == $cert13) or ($img2_type == $cert14) or ($img2_type == $cert15) or ($img2_type == $cert16) or ($img2_type == $cert17)) {
@copy($img2, "$abpath/$img2_name") or $log .= "Couldn't copy image 2 to server<br>";
if (file_exists("$abpath/$img2_name")) {
$log .= "File 2 was uploaded<br>";
}
} else {
$log .= "File 2 is not an image<br>";
}
}
}
}
//Upload #3
if ($img3_name == "") {
$log .= "No file selected for upload 3<br>";
}
if ($img3_name != "") {
//checks if file exists
if (file_exists("$abpath/$img3_name")) {
$log .= "File 3 already existed<br>";
} else {
//checks if files to big
if (($sizelim == "yes") && ($img3_size > $size)) {
$log .= "File 3 was too big<br>";
}
//Checks if file is an image
if (($img3_type == $cert1) or ($img3_type == $cert2) or ($img3_type == $cert3) or ($img3_type == $cert4) or ($img3_type == $cert5) or ($img3_type == $cert6) or ($img3_type == $cert7) or ($img3_type == $cert8) or ($img3_type == $cert9) or ($img3_type == $cert10) or ($img3_type == $cert11) or ($img3_type == $cert12) or ($img3_type == $cert13) or ($img3_type == $cert14) or ($img3_type == $cert15) or ($img3_type == $cert16) or ($img3_type == $cert17)) {
@copy($img3, "$abpath/$img3_name") or $log .= "Couldn't copy image 3 to server<br>";
if (file_exists("$abpath/$img3_name")) {
$log .= "File 3 was uploaded<br>";
}
} else {
$log .= "File 3 is not an image<br>";
}
}
}
if ($img4_name == "") {
$log .= "No file selected for upload 4<br>";
}
if ($img4_name != "") {
//checks if file exists
if (file_exists("$abpath/$img4_name")) {
$log .= "File 4 already existed<br>";
} else {
//checks if files to big
if (($sizelim == "yes") && ($img4_size > $size)) {
$log .= "File 4 was too big<br>";
} else {
//Checks if file is an image
if (($img4_type == $cert1) or ($img4_type == $cert2) or ($img4_type == $cert3) or ($img4_type == $cert4) or ($img4_type == $cert5) or ($img4_type == $cert6) or ($img4_type == $cert7) or ($img4_type == $cert8) or ($img4_type == $cert9) or ($img4_type == $cert10) or ($img4_type == $cert11) or ($img4_type == $cert12) or ($img4_type == $cert13) or ($img4_type == $cert14) or ($img4_type == $cert15) or ($img4_type == $cert16) or ($img4_type == $cert17)) {
@copy($img4, "$abpath/$img4_name") or $log .= "Couldn't copy image 4 to server<br>";
if (file_exists("$abpath/$img4_name")) {
$log .= "File 4 was uploaded<br>";
}
} else {
$log .= "File 4 is not an image<br>";
}
}
}
}
//Upload #5
if ($img5_name == "") {
$log .= "No file selected for upload 5<br>";
}
if ($img5_name != "") {
//checks if file exists
if (file_exists("$abpath/$img5_name")) {
$log .= "File 5 already existed<br>";
} else {
//checks if files to big
if (($sizelim == "yes") && ($img5_size > $size)) {
$log .= "File 5 was too big<br>";
} else {
//Checks if file is an image
if (($img5_type == $cert1) or ($img5_type == $cert2) or ($img5_type == $cert3) or ($img5_type == $cert4) or ($img5_type == $cert5) or ($img5_type == $cert6) or ($img5_type == $cert7) or ($img5_type == $cert8) or ($img5_type == $cert9) or ($img5_type == $cert10) or ($img5_type == $cert11) or ($img5_type == $cert12) or ($img5_type == $cert13) or ($img5_type == $cert14) or ($img5_type == $cert15) or ($img5_type == $cert16) or ($img5_type == $cert17)) {
@copy($img5, "$abpath/$img5_name") or $log .= "Couldn't copy image 5 to server<br>";
if (file_exists("$abpath/$img5_name")) {
$log .= "File 5 was uploaded<br>";
}
} else {
$log .= "File 5 is not an image<br>";
}
}
}
}
?>
<html>
<head>
<title>Image Report</title>
</head>
<body>
<p>Log:<br>
<?
echo "$log";
?>
</p>
<body>
<html>
I repeat! It's not mine! If anybody knows hos it is.. I would like 2 know.
I would allso like to get a critical eye at the code.. somethings doesent sem totally right here.... I think it could be done easier.
Try it.. I think i worcks just the way it is. ;]-
Thanks but I was looking for something a little more simple, that would deal with (text based) CSV files...
...I am too new to this PHP thing to be able to customise that huge script.
Thank you very, very much for the help...
...I am too new to this PHP thing to be able to customise that huge script.
Thank you very, very much for the help...
-
- Last Samuray
- Posts: 824
- Joined: Sun Jun 02, 2002 3:09 am
weit to the evening I will give you awnswer =).
I am to busy almost all day! (work =))
I am to busy almost all day! (work =))
-
- Last Samuray
- Posts: 824
- Joined: Sun Jun 02, 2002 3:09 am
exemple script
Code: Select all
<?php
$files=5;// how mach file you wants to upload
if (!isset($form)){
echo "<form method=POST action=$PHP_SELF enctype=multipart/form-data>";
for ($i=1; $i <= $files; $i++)
{
echo "File <b>$i</b> <input type=file name=file$i><br>";
}
echo "<input type=hidden name=form value=0>
<input type=submit value=upload>";
}
if (isset($form))
{
for ($i=1; $i <= $files; $i++)
{
$filename="file$i";
copy ($HTTP_POST_FILES[$filename]['tmp_name'], $i);
}
}
?>
I have a question re your code. Instead of uploading multiple files, what if I wanted to upload multiple values into the same table.
ie: red, (next record:) blue, (next record:) green
Is there something to replace
copy ($HTTP_POST_FILES[$filename]['tmp_name'], $i);
by an insert?
I have been struggling for this one for ages.
ie: red, (next record:) blue, (next record:) green
Is there something to replace
copy ($HTTP_POST_FILES[$filename]['tmp_name'], $i);
by an insert?
I have been struggling for this one for ages.
-
- Last Samuray
- Posts: 824
- Joined: Sun Jun 02, 2002 3:09 am
yes.
for ($i=0; $1 < "10"; $i++)
{
${"value".$i}; // value
}
for ($i=0; $1 < "10"; $i++)
{
${"value".$i}; // value
}
- WiZARD
- Moderator
- Posts: 1240
- Joined: Thu Jun 20, 2002 10:14 pm
- Location: Ukraine, Crimea, Simferopol
- Contact:
atw wrote:How do I change the upload destination???
see http://www.php.net/manual/en/function.copy.php and i think that you understand....
"Sex,Drugs and Rock&Roll " replaced at "Sucks,Bugs and Plug&Play";


<?php
$files=1;// how many file(s) you want to upload...
//$location="http://www.atwright.com/averages/"
if (!isset($form)){
echo "<form method=POST action=$PHP_SELF enctype=multipart/form-data>";
for ($i=1; $i <= $files; $i++)
{
echo "File <b>$i</b> <input type=file name=file$i><br>";
}
echo "<input type=hidden name=form value=0>
<input type=submit value=upload>";
}
if (isset($form))
{
for ($i=1; $i <= $files; $i++)
{
$filename="file$i.csv";
copy ($_FILES[$filename]['tmp_name'], "/home/atwright/public_html/averages/$filename");
}
}
?>
How would I go about changing this code so that the uploading files keep their original names AND have lowercase names?
Also, is it possible to make it choose a folder and upload all the files in the folder instead of IDing them all individually?
Thanks for any help

-
- Last Samuray
- Posts: 824
- Joined: Sun Jun 02, 2002 3:09 am
must read
http://www.php.net/manual/en/function.strtolower.php
$_FILES[$filename]['name'] - origginal name of the file
yes it posible to changr a folder =)
http://www.php.net/manual/en/function.strtolower.php
$_FILES[$filename]['name'] - origginal name of the file
yes it posible to changr a folder =)
Okay, just to rephrase, how would I change the script to make it upload the contents of folder? You must forgive me; though I am intellegent enough to fill in a lot of gaps and/or adjust simple code to my needs I am actually more at home with Macromedia's Lingo than PHP.
What do I then change about the path? Would: "/home/atwright/public_html/averages/$name"); work?
Sorry for being such an info leech...
...when I understand PHP a little more I'll try to start giving back :lol:
copy ($_FILES[$filename]['tmp_name'], "/home/atwright/public_html/averages/$filename");
What do I then change about the path? Would: "/home/atwright/public_html/averages/$name"); work?

Sorry for being such an info leech...
...when I understand PHP a little more I'll try to start giving back :lol:
-
- Last Samuray
- Posts: 824
- Joined: Sun Jun 02, 2002 3:09 am
Code: Select all
copy ($_FILES[$filename]['tmp_name'], "/home/atwright/public_html/averages/".$filename);
-
- Last Samuray
- Posts: 824
- Joined: Sun Jun 02, 2002 3:09 am
I do not understand, that is essentially the same piece of code is it not?
it is more practise pice of code =)
it is more practise pice of code =)
I'm sorry I don't understand, Practise???
Will this allow me to upload the contents of folder or just a file?
If it is just for singular files, do I need to remove the line:
$filename="file$i.csv";

-
- Last Samuray
- Posts: 824
- Joined: Sun Jun 02, 2002 3:09 am
ok,
as my English so bad i will tell in this way.
Yes, your script is good.
and you do not need remove that line
as my English so bad i will tell in this way.
Yes, your script is good.
and you do not need remove that line
I like some of the functions in the script i suggested in the beginning of this topic.
But there is a code I want to add, but I dont know how to do it!
And I want it to do something like this:
It's okay to know if the file already exists, and if you have a new one and want to overwrite you can.
Any suggestons?
But there is a code I want to add, but I dont know how to do it!
Code: Select all
//checks if file exists
if ($img1_name == "") {
$log .= "No file selected for upload 1<br>";
}
if ($img1_name != "") {
//checks if file exists
if (file_exists("$abpath/$img1_name")) {
$log .= "File 1 already existed<br>";
} else {
And I want it to do something like this:
Code: Select all
//checks if file exists
if ($img1_name == "") {
$log .= "No file selected for upload 1<br>";
}
if ($img1_name != "") {
//checks if file exists
if (file_exists("$abpath/$img1_name")) {
$log .= " <form method=POST action=??> File 1 already existed: <br>Owerwrite ".$img1_name."? <input name=Overwrite type="checkbox" value=??><b> Yes!</b><br><input type="Submit" name="submit"></form>";
} else {
It's okay to know if the file already exists, and if you have a new one and want to overwrite you can.
Any suggestons?
-
- Last Samuray
- Posts: 824
- Joined: Sun Jun 02, 2002 3:09 am
if (if_file_exist($file))
{
}

{
}
