New Image Uploads

I have been playing around with this upload code

[php]

<?php $numoffile = 5; $file_dir = "uploads/"; if ($_POST) { for ($i=0;$i<$numoffile;$i++) { if (trim($_FILES['myfiles']['name'][$i])!="") { $newfile = $file_dir.$_FILES['myfiles']['name'][$i]; move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile); $j++; } } } if (isset($j)&&$j>0) print "Your file(s) has been uploaded.
"; print ""; for($i=0;$i<$numoffile;$i++) { print "
"; } print ""; print ""; ?>

[/php]

Its working but I want to rename the files so they are sequential, this is for an image gallery I have designed

Anyone have any suggestions

[php]<?php
$numoffile = 5;
$file_dir = “uploads/”;

if (isset($_POST[‘action’]) && $_POST[‘action’] == “Upload”)
{
for ($i=0; $i < $numoffile; $i++)
{
if (trim($_FILES[‘myfiles’][‘name’][$i]) != “”)
{
$newfile = $file_dir . $_FILES[‘myfiles’][‘name’][$i];
move_uploaded_file($_FILES[‘myfiles’][‘tmp_name’][$i], $newfile);
$j++;
}
}
}
if (isset($j) && $j>0)
{
print “Your file(s) has been uploaded.
”;
}
?>

<?php for($i=0; $i < $numoffile; $i++) { ?>
 <input type="file" name="myfiles[]" size="30"><br>
<?php } ?> This is not actually here ->[/php]

I cleaned up the code, to make it easier, at least to me, to read. Anyway, what is or isn’t working?

Hi Ragster00

The above is working ok what I was tryng to do was upload multiple images and rename them on the fly.

I’ve sorted it now with a bit of messing about. Here is the code. Thanks for cleaning it up.

[php]

<?php $numoffile = 5; $file_dir = "uploads/a001/"; if (isset($_POST['action']) && $_POST['action'] == "Upload") { for ($i=0; $i < $numoffile; $i++) { if (trim($_FILES['myfiles']['name'][$i]) != "") { $newfile = $file_dir . "$i.jpg"; move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile); $j++; } } } if (isset($j) && $j>0) { print "Your file(s) has been uploaded.
"; } ?> <?php for($i=0; $i < $numoffile; $i++) { ?>
 <input type="file" name="myfiles[]" size="30"><br> 
<?php } ?>

<img src="<?php echo "uploads/a001/$i.jpg" ?>">
<img src="<?php echo "uploads/a001/1.jpg" ?>">
<img src="<?php echo "uploads/a001/2.jpg" ?>">
<img src="<?php echo "uploads/a001/3.jpg" ?>">
<img src="<?php echo "uploads/a001/4.jpg" ?>">
<img src="<?php echo "uploads/a001/5.jpg" ?>">

[/php]

By the way i know its not a php question but when I preview a webpage in IE6 running XP_Pro i always have to f5 the browser before i can see the changes, any suggestions or is it an inherant fault with IE6

To see what changes? Changes you have just made? You always have to hit refresh to see any changes done to a web page after changes have been made.

Or do you mean that the refresh button doesn’t do the trick. Sometimes, it takes a hard refresh to get changes to appear. shift + refresh button forces the browser to go and download the page again, instead of just pulling it from cache.

I changed

[php]
$newfile = $file_dir . $_FILES[‘myfiles’][‘name’][$i];
[/php]

to

[php]
$newfile = $file_dir . “$i.jpg”;
[/php]

I have also made the following change since

[php]

" width="50px" height="37px">
[/php]

Using the above code how would I go about setting the maximum image dimensions and file size and type of image that can be uploaded

I know its
[php]

$maxwidth = 350; 
$maxheight = 250; 
$max_filesize = 102400; 

$uploads = 'uploads/a001'; 
$types_array = array('image/gif','image/pjpeg','image/x-png'); 

[/php]

but where would I put the code

Depends on how you want to do it. Do you want to check the file then notify the user that they can’t upload something bigger than what ever you specify or do you want it so the code reduces the size for them?

If I can reduce the file size that would be better, didn’t realise you could do that

I do not have to much experience with this, I just know it can be done with GD. To get in the right direction you can search of terms like GDLib, GD Library, Images and PHP. You will need to make sure this module is installed on the server as well. To find that out you can use your phpinfo page.

Thanks Ragster at least I know what to look for

Andy

Sponsor our Newsletter | Privacy Policy | Terms of Service