Jump to content

Recommended Posts

I have downloaded a script for a multiple file upload.  I wanted to edit it with a list box, so that what option the user chooses with the list box decides what directory the file will be uploaded to.

 

Here is the upload page.

 

<table width="500" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<form action="multiple_upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1">
<tr>
<td>Please Select a Gallery:</td>
</tr>
<tr>
<td><select name="gallery">
  <option value="images/gallery/upload/HarlanSpring08">Harlan Spring '08</option>
  <option value="HarlanFall08">Harlan Fall '08</option>
  <option value="Local">Local</option>
  <option value="Tellico06">Tellico '06</option>
  <option value="Tellico07">Tellico '07</option>
  <option value="Other">Other</option>
</select><td>
</tr>
<tr>
<td><strong>multiple Files Upload </strong></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>

 

and here is the upload script

 

<?php
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0];
$path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1];
$path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2];

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

 

where it says $path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0]; i want it to direct the folder to what ever the value is of the select box.  That value will correspond with a directory on the website and then will dump the image there.

 

For some reason i'm drawing a blank on how to do this so i was hoping for some help.

Link to comment
https://forums.phpfreaks.com/topic/158417-listbox-verifys-path-of-upload/
Share on other sites

It is now acting like it is uploading the file, but the file is still not being uploaded.  Where you had me change the $HTTP_POST_FILES to $_POST, should i do that every where there is a $HTTP_POST_FILES?

 

Here is the rest of the code so you can see it.

 

<?php
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path1= $_POST['gallery']."/".$_FILES['ufile']['name'][0];
$path1= $_POST['gallery']."/".$_FILES['ufile']['name'][1];
$path1= $_POST['gallery']."/".$_FILES['ufile']['name'][2];

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

//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>";
echo "<img src=\"$path1\" width=\"150\" height=\"150\">";
echo "<P>";

echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>";
echo "<img src=\"$path2\" width=\"150\" height=\"150\">";
echo "<P>";

echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>";
echo "<img src=\"$path3\" width=\"150\" height=\"150\">";

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

 

there is more below but it just has to do with displaying errors and i figured it was not needed.

You need to make sure the folders exist and have write access

 

here's some sample code with a little error checking

<?php
foreach($_FILES['ufile']['name'] as $K => $Name)
{
$uploaddir= $_POST['gallery']."/";
//check folder path
if(!is_dir($uploaddir)) die("Can't upload invalid folder path: $uploaddir");

$path= $uploaddir.$Name;
//copy file to where you want to store file
$valid = copy($_FILES['ufile']['tmp_name'][$K], $path);
if($valid)
{
echo "File Name :$Name<BR/>";
echo "File Size :".$_FILES['ufile']['size'][$K]."<BR/>";
echo "File Type :".$_FILES['ufile']['type'][$K]."<BR/>";
echo "<img src=\"$path\" width=\"150\" height=\"150\">";
}else{
echo "failed: ";
}
echo "<P>";
}

The verification works fine it comes back good.  And i have it echo me the path it is supposed to store it in and that comes back correct, but the image is not saving in there for some odd reason.  I gave the folder the correct permissions, but it is still not dumping the image in there.  Is there something wrong with the code, or a way i can change it around to do the same thing?

Well I thought i had it wooped.  I got it all working, but only tested with one.  Now I run into the problem that i have 3 boxes where you can upload 3 pictures at a time.  The script works and uploads the first properly, but the 2nd a 3rd image don't upload properly.

 

$folder =$_POST['gallery'];
$path1= "images/gallery/upload/".$folder.'/'.$HTTP_POST_FILES['ufile']['name'][0];
$path2= "images/gallery/upload/".$folder.'/'.$HTTP_POST_FILES['ufile']['name'][1];
$path3= "images/gallery/upload/".$folder.'/'.$HTTP_POST_FILES['ufile']['name'][2]; 

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

//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>";
echo "<img src=\"$path1\" width=\"150\" height=\"150\">";
echo "<P>";

echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>";
echo "<img src=\"$path2\" width=\"150\" height=\"150\">";
echo "<P>";

echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>";
echo "<img src=\"$path3\" width=\"150\" height=\"150\">";

 

Not sure what I could change to make it work.  Everything seems to be solid on the code.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.