Woodburn2006 Posted August 29, 2006 Share Posted August 29, 2006 i am doing an upload page for a picture gallery. the user will be uploading more than one image. what i want to do is, is for every picture that is uploaded i want to rename with the artists name and have a sequental number following it. for example: [list][*]artistname1[*]artistname2[*]artistname3[*]artistname4[*]etc etc[/list]how would i do this when i use the following code to upload:[code]<?phpforeach ($_FILES["pictures"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; $name = $_FILES["pictures"]["name"][$key]; move_uploaded_file($tmp_name, "images/$name"); }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/19026-re-naming-uploaded-files/ Share on other sites More sharing options...
SharkBait Posted August 29, 2006 Share Posted August 29, 2006 Hopefully this works, the idea is there anyway ;)[code]<?php$i = 1; // Counterforeach ($_FILES["pictures"]["error"] as $key => $error) { list($artistname, $extension) = explode(".", $_FILES['name'][$key]); // seperate name from extension if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; $name = $_FILES["pictures"]["name"][$key]; move_uploaded_file($tmp_name, "images/{$artistname}{$i}.{$extension}"); } $i++;}?>[/code]Though this wouldnt take into account of the artist has uploaded in past. That would involve seeing how many files they already have uploaded and starting $i at that point and then continuing the increment. Link to comment https://forums.phpfreaks.com/topic/19026-re-naming-uploaded-files/#findComment-82274 Share on other sites More sharing options...
Woodburn2006 Posted August 29, 2006 Author Share Posted August 29, 2006 cool thanks, what would i use to get the list of files that were previously use and then get the highest number?im assuming that i would fetch the highest labelled number then split the artist name from the number and extension so that i would have a figure to set as $i? Link to comment https://forums.phpfreaks.com/topic/19026-re-naming-uploaded-files/#findComment-82276 Share on other sites More sharing options...
Woodburn2006 Posted August 29, 2006 Author Share Posted August 29, 2006 i used this code like was said to use, but the outputted image has no extension, it renames the files fine but there is no extension on the image.[code]<?php$comp = $_POST["comp"];$col = $_POST["col"];$i = 1; // Counterforeach ($_FILES["pictures"]["error"] as $key => $error) { list($artistname, $extension) = explode(".", $_FILES['name'][$key]); // seperate name from extension if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; $name = $_FILES["pictures"]["name"][$key]; move_uploaded_file($tmp_name, "tests/{$comp}{$i}.{$extension}"); echo "done<br>"; } $i++;}?>[/code] Link to comment https://forums.phpfreaks.com/topic/19026-re-naming-uploaded-files/#findComment-82288 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.