...

View Full Version : Multi Upload



jamesk
02-27-2010, 10:01 PM
Hey,

I have recently coded a fully functional image hosting script (first php project for me...) but it's only single upload!

Can anyone tell me what I need to do to make it multi upload please?

index.php:


<font size="1"><b>Select file to upload: </b></font><input name="image" type="file" size="60" class="upload">
<p align=center><input name="Submit" type="submit" value="Upload" class="button" onclick = 'this.style.display = "none"; document.getElementById("loading1").style.display = ""' />
<img src = 'images/loading.gif' border = '0' alt = 'Loading' id = 'loading1' style = 'display: none;'/><br /><br />

upload.php:

<?php
define ("MAX_SIZE","1048576000");

include("config.php");

function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
$typesallowed = array("jpg", "jpeg", "JPG", "JPEG", "pdf", "png", "txt", "zip", "bmp", "gif", "css");
if (!in_array("$extension", $typesallowed))
{
//print error message
echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
<font face=verdana size=1 color=black>You have tried to upload an invalid extension! Please try again!</font>';
$errors=1;
}
else
{

$size=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1048576000)
{
echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
<font face=verdana size=1 color=black>You have exceeded the file upload limit! Please upload a smaller image.</font>';
$errors=1;
}

//we will give an unique name, for example the time in unix time format
$max_filename_chars = 5;
function getUniqueCode($length = "8")
{
$code = md5(uniqid(rand(), true));
if ($length != "") return substr($code, 0, $length);
else return $code;
}

$image_name=getUniqueCode().'.'.$extension;
$mymymy = substr($image_name, 5);
$newname="1/".$mymymy;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
<font face=verdana size=1 color=black>Upload unsuccessful. Either you did not select an image to upload or there has been another error.</font>';
$errors=1;
}}}}

//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
echo "<p align=center><font face=verdana size=4><b><a href=$newname>View your Upload</a></font><br /<br />";
echo "<b><font face=verdana size=1>File Link:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input value=http://jameskealey.po.gs/pick/$newname style= width:45% class='bx' onclick='this.select()'><br \><br \>";
$types = array("txt", "pdf", "zip");
if (in_array("$extension", $types)) {
echo "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
echo "<font face=verdana size=1><a href=http:////twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></font></p>";

} else {
echo "<b>UBBC Code:</b></font><input class='bx' onclick='this.select()' value=";
echo "http://jameskealey.po.gs/pick/";
echo $newname;
echo " style=width:45%><br>";
echo "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
echo "<font face=verdana size=1><a href=http://twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></p></b>";
$info=getimagesize("$newname");
// display image details (only shown for images...)
echo "Dimensions: ".$info[0]." x ".$info[1]."<br />";
echo "Image type: ".$info[mime]."<br />";
echo "Image size: ".$info[bits]." kB<br />";
echo "</font>";
}



$ip = getenv("REMOTE_ADDR");
include('config.php');
$link=mysql_connect($data_server, $data_user, $data_pw);
mysql_select_db("jkealey");
mysql_query("INSERT INTO image_table
(image, ip) VALUES('$newname', '$ip' ) ")
or die(mysql_error());

}

?>


Any help would be appriciated. I can't find a way to do multi upload. I don't want to use two different scripts etc...

James

F00Baron
02-27-2010, 11:03 PM
change the html to have two(or more) input tags:

Upload 1: <input name="file_upload[0]" type="file" size="25"/><br>
Upload 2: <input name="file_upload[1]" type="file" size="25"/><br>


Then if the user uploads two, the $_FILES superglobal will have another dimension, so:

if(is_array($_FILES['file_upload']['name'])) {
foreach($_FILES['file_upload']['name'] as $i=>$unused) {
$extraDigit = (($i==0) ? '':$i+1);
if(file_exists($_FILES['file_upload']['tmp_name'][$i])) {
handleUploadFile($_FILES['file_upload']['tmp_name'][$i],$_FILES['file_upload']['name'][$i]);
}
}
} else {
if((isset($_FILES['file_upload'])) && ($_FILES['file_upload']['name']) && ($_FILES['file_upload']['tmp_name'] != 'none')) {
handleUploadFile($_FILES['file_upload']['tmp_name'],$_FILES['file_upload']['name']);
}
}

jamesk
02-27-2010, 11:13 PM
Ok, thanks very much - but where does that go in my code?

can you possible put it in the code for me? and then how would i get the amount of input fields to display the links at the bottom?

Understand me? Sorry if i seem a little vague!

PM me if you are unsure :)

James

jamesk
03-04-2010, 07:15 PM
Can anyone tell me where to put:



if(is_array($_FILES['file_upload']['name'])) {
foreach($_FILES['file_upload']['name'] as $i=>$unused) {
$extraDigit = (($i==0) ? '':$i+1);
if(file_exists($_FILES['file_upload']['tmp_name'][$i])) {
handleUploadFile($_FILES['file_upload']['tmp_name'][$i],$_FILES['file_upload']['name'][$i]);
}
}
} else {
if((isset($_FILES['file_upload'])) && ($_FILES['file_upload']['name']) && ($_FILES['file_upload']['tmp_name'] != 'none')) {
handleUploadFile($_FILES['file_upload']['tmp_name'],$_FILES['file_upload']['name']);
}
}


in my original script? I can't seem to get it to work.

Any help would be fantastic.

Cheers,
James

jamesk
03-07-2010, 11:48 AM
I would really like this script to work - can anyone please help.

_Aerospace_Eng_
03-07-2010, 05:11 PM
Okay so WHAT have you tried? We are here to help but we aren't here to just code for you. Show us that you actually tried to do yourself and we can tell you where you went wrong. If aren't willing to do that then I suggest you hire a professional.

jamesk
03-07-2010, 06:23 PM
I have tried to place the code in several different places, and I can't get it to upload the images correctly.

_Aerospace_Eng_
03-07-2010, 06:57 PM
Then post the code you tried to use.

jamesk
03-07-2010, 07:10 PM
If possible, I would like to know where to put:


if(is_array($_FILES['file_upload']['name'])) {
foreach($_FILES['file_upload']['name'] as $i=>$unused) {
$extraDigit = (($i==0) ? '':$i+1);
if(file_exists($_FILES['file_upload']['tmp_name'][$i])) {
handleUploadFile($_FILES['file_upload']['tmp_name'][$i],$_FILES['file_upload']['name'][$i]);
}
}
} else {
if((isset($_FILES['file_upload'])) && ($_FILES['file_upload']['name']) && ($_FILES['file_upload']['tmp_name'] != 'none')) {
handleUploadFile($_FILES['file_upload']['tmp_name'],$_FILES['file_upload']['name']);
}
}

in:


<?php
define ("MAX_SIZE","1048576000");

include("config.php");

function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
$typesallowed = array("jpg", "jpeg", "JPG", "JPEG", "pdf", "png", "txt", "zip", "bmp", "gif", "css");
if (!in_array("$extension", $typesallowed))
{
//print error message
echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
<font face=verdana size=1 color=black>You have tried to upload an invalid extension! Please try again!</font>';
$errors=1;
}
else
{

$size=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1048576000)
{
echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
<font face=verdana size=1 color=black>You have exceeded the file upload limit! Please upload a smaller image.</font>';
$errors=1;
}

//we will give an unique name, for example the time in unix time format
$max_filename_chars = 5;
function getUniqueCode($length = "8")
{
$code = md5(uniqid(rand(), true));
if ($length != "") return substr($code, 0, $length);
else return $code;
}

$image_name=getUniqueCode().'.'.$extension;
$mymymy = substr($image_name, 5);
$newname="1/".$mymymy;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
<font face=verdana size=1 color=black>Upload unsuccessful. Either you did not select an image to upload or there has been another error.</font>';
$errors=1;
}}}}

//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
echo "<p align=center><font face=verdana size=4><b><a href=$newname>View your Upload</a></font><br /<br />";
echo "<b><font face=verdana size=1>File Link:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input value=http://jameskealey.po.gs/pick/$newname style= width:45% class='bx' onclick='this.select()'><br \><br \>";
$types = array("txt", "pdf", "zip");
if (in_array("$extension", $types)) {
echo "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
echo "<font face=verdana size=1><a href=http:////twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></font></p>";

} else {
echo "<b>UBBC Code:</b></font><input class='bx' onclick='this.select()' value=";
echo "http://jameskealey.po.gs/pick/";
echo $newname;
echo " style=width:45%><br>";
echo "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
echo "<font face=verdana size=1><a href=http://twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></p></b>";
$info=getimagesize("$newname");
// display image details (only shown for images...)
echo "Dimensions: ".$info[0]." x ".$info[1]."<br />";
echo "Image type: ".$info[mime]."<br />";
echo "Image size: ".$info[bits]." kB<br />";
echo "</font>";
}



$ip = getenv("REMOTE_ADDR");
include('config.php');
$link=mysql_connect($data_server, $data_user, $data_pw);
mysql_select_db("jkealey");
mysql_query("INSERT INTO image_table
(image, ip) VALUES('$newname', '$ip' ) ")
or die(mysql_error());

}

?>

To allow the user to upload more than one file. Also, how would I show the links for the second file that was uploaded on the upload.php page?

James

_Aerospace_Eng_
03-07-2010, 07:47 PM
You aren't getting what I'm asking you. Try to put the code that was given to you inside of your existing code and then post exactly what you tried.

jamesk
03-07-2010, 08:24 PM
<?php
define ("MAX_SIZE","1048576000");

include("config.php");

function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
$typesallowed = array("jpg", "jpeg", "JPG", "JPEG", "pdf", "png", "txt", "zip", "bmp", "gif", "css");
if (!in_array("$extension", $typesallowed))
{
//print error message
echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
<font face=verdana size=1 color=black>You have tried to upload an invalid extension! Please try again!</font>';
$errors=1;
}
else
{

$size=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1048576000)
{
echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
<font face=verdana size=1 color=black>You have exceeded the file upload limit! Please upload a smaller image.</font>';
$errors=1;
}

//we will give an unique name, for example the time in unix time format
$max_filename_chars = 5;
function getUniqueCode($length = "8")
{
$code = md5(uniqid(rand(), true));
if ($length != "") return substr($code, 0, $length);
else return $code;
}

$image_name=getUniqueCode().'.'.$extension;
$mymymy = substr($image_name, 5);
$newname="1/".$mymymy;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
<font face=verdana size=1 color=black>Upload unsuccessful. Either you did not select an image to upload or there has been another error.</font>';
$errors=1;
}}}}

if(is_array($_FILES['file_upload']['name'])) {
foreach($_FILES['file_upload']['name'] as $i=>$unused) {
$extraDigit = (($i==0) ? '':$i+1);
if(file_exists($_FILES['file_upload']['tmp_name'][$i])) {
handleUploadFile($_FILES['file_upload']['tmp_name'][$i],$_FILES['file_upload']['name'][$i]);
}
}
} else {
if((isset($_FILES['file_upload'])) && ($_FILES['file_upload']['name']) && ($_FILES['file_upload']['tmp_name'] != 'none')) {
handleUploadFile($_FILES['file_upload']['tmp_name'],$_FILES['file_upload']['name']);
}
}

//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
echo "<p align=center><font face=verdana size=4><b><a href=$newname>View your Upload</a></font><br /<br />";
echo "<b><font face=verdana size=1>File Link:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input value=http://jameskealey.po.gs/pick/$newname style= width:45% class='bx' onclick='this.select()'><br \><br \>";
$types = array("txt", "pdf", "zip");
if (in_array("$extension", $types)) {
echo "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
echo "<font face=verdana size=1><a href=http:////twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></font></p>";

} else {
echo "<b>UBBC Code:</b></font><input class='bx' onclick='this.select()' value=";
echo "http://jameskealey.po.gs/pick/";
echo $newname;
echo " style=width:45%><br>";
echo "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
echo "<font face=verdana size=1><a href=http://twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></p></b>";
$info=getimagesize("$newname");
// display image details (only shown for images...)
echo "Dimensions: ".$info[0]." x ".$info[1]."<br />";
echo "Image type: ".$info[mime]."<br />";
echo "Image size: ".$info[bits]." kB<br />";
echo "</font>";
}



$ip = getenv("REMOTE_ADDR");
include('config.php');
$link=mysql_connect($data_server, $data_user, $data_pw);
mysql_select_db("jkealey");
mysql_query("INSERT INTO image_table
(image, ip) VALUES('$newname', '$ip' ) ")
or die(mysql_error());

}

?>

jamesk
03-15-2010, 04:32 PM
Any more help on this please? I understand I'm asking a lot...

James

jamesk
03-17-2010, 08:31 PM
I do apolagise about this - I am asking is someone can tell me what do to this script:


<?php
define ("MAX_SIZE","1048576000");

include("config.php");

function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
$typesallowed = array("jpg", "jpeg", "JPG", "JPEG", "pdf", "png", "txt", "zip", "bmp", "gif", "css");
if (!in_array("$extension", $typesallowed))
{
//print error message
echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
<font face=verdana size=1 color=black>You have tried to upload an invalid extension! Please try again!</font>';
$errors=1;
}
else
{

$size=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1048576000)
{
echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
<font face=verdana size=1 color=black>You have exceeded the file upload limit! Please upload a smaller image.</font>';
$errors=1;
}

//we will give an unique name, for example the time in unix time format
$max_filename_chars = 5;
function getUniqueCode($length = "8")
{
$code = md5(uniqid(rand(), true));
if ($length != "") return substr($code, 0, $length);
else return $code;
}

$image_name=getUniqueCode().'.'.$extension;
$mymymy = substr($image_name, 5);
$newname="1/".$mymymy;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
<font face=verdana size=1 color=black>Upload unsuccessful. Either you did not select an image to upload or there has been another error.</font>';
$errors=1;
}}}}

//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
echo "<p align=center><font face=verdana size=4><b><a href=$newname>View your Upload</a></font><br /<br />";
echo "<b><font face=verdana size=1>File Link:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input value=http://jameskealey.po.gs/pick/$newname style= width:45% class='bx' onclick='this.select()'><br \><br \>";
$types = array("txt", "pdf", "zip");
if (in_array("$extension", $types)) {
echo "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
echo "<font face=verdana size=1><a href=http:////twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></font></p>";

} else {
echo "<b>UBBC Code:</b></font><input class='bx' onclick='this.select()' value=";
echo "http://jameskealey.po.gs/pick/";
echo $newname;
echo " style=width:45%><br>";
echo "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
echo "<font face=verdana size=1><a href=http://twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></p></b>";
$info=getimagesize("$newname");
// display image details (only shown for images...)
echo "Dimensions: ".$info[0]." x ".$info[1]."<br />";
echo "Image type: ".$info[mime]."<br />";
echo "Image size: ".$info[bits]." kB<br />";
echo "</font>";
}



$ip = getenv("REMOTE_ADDR");
include('config.php');
$link=mysql_connect($data_server, $data_user, $data_pw);
mysql_select_db("jkealey");
mysql_query("INSERT INTO image_table
(image, ip) VALUES('$newname', '$ip' ) ")
or die(mysql_error());

}

?>

To make it multi upload. Someone has already given me:


if(is_array($_FILES['file_upload']['name'])) {
foreach($_FILES['file_upload']['name'] as $i=>$unused) {
$extraDigit = (($i==0) ? '':$i+1);
if(file_exists($_FILES['file_upload']['tmp_name'][$i])) {
handleUploadFile($_FILES['file_upload']['tmp_name'][$i],$_FILES['file_upload']['name'][$i]);
}
}
} else {
if((isset($_FILES['file_upload'])) && ($_FILES['file_upload']['name']) && ($_FILES['file_upload']['tmp_name'] != 'none')) {
handleUploadFile($_FILES['file_upload']['tmp_name'],$_FILES['file_upload']['name']);
}
}

and told me to change my original index.php page to:

Upload 1: <input name="file_upload[0]" type="file" size="25"/><br>
Upload 2: <input name="file_upload[1]" type="file" size="25"/><br>

but everywhere I put that code to allow the multi upload - it either doesn't work or i get errors!

Any help? I will give FTP access to people if required.

I hope someone can help me here, I'm so close I think :P...

James

jamesk
05-15-2010, 05:28 PM
Sorry for bumping this 2 months later, but I still can't get it to work.

This my simple upload script:

<?php
define ("MAX_SIZE","1048576000");

include("config.php");

function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
$typesallowed = array("jpg", "jpeg", "JPG", "JPEG", "pdf", "png", "txt", "zip", "bmp", "gif", "css");
if (!in_array("$extension", $typesallowed))
{
//print error message
echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
<font face=verdana size=1 color=black>You have tried to upload an invalid extension! Please try again!</font>';
$errors=1;
}
else
{

$size=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1048576000)
{
echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
<font face=verdana size=1 color=black>You have exceeded the file upload limit! Please upload a smaller image.</font>';
$errors=1;
}

//we will give an unique name, for example the time in unix time format
$max_filename_chars = 5;
function getUniqueCode($length = "8")
{
$code = md5(uniqid(rand(), true));
if ($length != "") return substr($code, 0, $length);
else return $code;
}

$image_name=getUniqueCode().'.'.$extension;
$mymymy = substr($image_name, 5);
$newname="1/".$mymymy;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
<font face=verdana size=1 color=black>Upload unsuccessful. Either you did not select an image to upload or there has been another error.</font>';
$errors=1;
}}}}

//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
echo "<p align=center><font face=verdana size=4><b><a href=$newname>View your Upload</a></font><br /<br />";
echo "<b><font face=verdana size=1>File Link:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input value=http://jameskealey.po.gs/pick/$newname style= width:45% class='bx' onclick='this.select()'><br \><br \>";
$types = array("txt", "pdf", "zip");
if (in_array("$extension", $types)) {
echo "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
echo "<font face=verdana size=1><a href=http:////twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></font></p>";

} else {
echo "<b>UBBC Code:</b></font><input class='bx' onclick='this.select()' value=";
echo "http://jameskealey.po.gs/pick/";
echo $newname;
echo " style=width:45%><br>";
echo "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
echo "<font face=verdana size=1><a href=http://twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></p></b>";
$info=getimagesize("$newname");
// display image details (only shown for images...)
echo "Dimensions: ".$info[0]." x ".$info[1]."<br />";
echo "Image type: ".$info[mime]."<br />";
echo "Image size: ".$info[bits]." kB<br />";
echo "</font>";
}



$ip = getenv("REMOTE_ADDR");
include('config.php');
$link=mysql_connect($data_server, $data_user, $data_pw);
mysql_select_db("jkealey");
mysql_query("INSERT INTO image_table
(image, ip) VALUES('$newname', '$ip' ) ")
or die(mysql_error());

}

?>

To make it multi-upload, I need to put:

if(is_array($_FILES['file_upload']['name'])) {
foreach($_FILES['file_upload']['name'] as $i=>$unused) {
$extraDigit = (($i==0) ? '':$i+1);
if(file_exists($_FILES['file_upload']['tmp_name'][$i])) {
handleUploadFile($_FILES['file_upload']['tmp_name'][$i],$_FILES['file_upload']['name'][$i]);
}
}
} else {
if((isset($_FILES['file_upload'])) && ($_FILES['file_upload']['name']) && ($_FILES['file_upload']['tmp_name'] != 'none')) {
handleUploadFile($_FILES['file_upload']['tmp_name'],$_FILES['file_upload']['name']);
}
}

somewhere - someone suggested this earlier.

Also, I have now change index.php so it can accept multi uploads:

Upload 1: <input name="file_upload[0]" type="file" size="25"/><br>
Upload 2: <input name="file_upload[1]" type="file" size="25"/><br>

but everywhere I put that code to allow the multi upload - it either doesn't work or i get errors!

Any help? I will give FTP access to people if required.


James

scoop_987
05-15-2010, 05:49 PM
Hey, PM me and i'll re-code it for you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum