czukoman20 Posted November 20, 2007 Share Posted November 20, 2007 Well i have this upload bar code that i was just wondering how i would be able to manipulate this code i have here to upload the file, then give it a different name to it but still keep the extension on the end like if i uploaded a file called 103_2893.jpg... it would rename it to example.jpg then i would need to be able to overwrite it if there is a file in there already with that name <?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 $path= "upload/".$HTTP_POST_FILES['ufile']['name']; if($ufile !=none) { if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)) { echo "Successful<BR/>"; //$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']."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; echo "<img src=\"$path\" width=\"150\" height=\"150\">"; } else { echo "Error"; } } ?> help is greatly appreciated thanks Link to comment https://forums.phpfreaks.com/topic/78126-solved-upload-bar-enhanced/ Share on other sites More sharing options...
czukoman20 Posted November 20, 2007 Author Share Posted November 20, 2007 Anyone? Link to comment https://forums.phpfreaks.com/topic/78126-solved-upload-bar-enhanced/#findComment-395384 Share on other sites More sharing options...
quasiman Posted November 26, 2007 Share Posted November 26, 2007 This should work <?php //This function separates the extension from the rest of the file name and returns it function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } //This applies the function to your file $ext = findexts ($_FILES['uploaded']['name']) ; //This is your new file name $new = "example"; //This adds a . on the end, so it is ready of the file extension to be appended. $new2 = $new."."; //This assigns the subdirectory you want to save into $target = "images/"; //This combines the directory, the file name, and the extension $target = $target . $new2.$ext; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file has been uploaded as ".$new2.$ext."<br />"; //$HTTP_POST_FILES['ufile']['name'] = file name //$HTTP_POST_FILES['ufile']['size'] = file size //$HTTP_POST_FILES['ufile']['type'] = type of file echo "Original File Name :".$_FILES['uploaded']['name']."<BR/>"; echo "File Size :".$_FILES['uploaded']['size']."<BR/>"; echo "File Type :".$_FILES['uploaded']['type']."<BR/>"; echo "<img src=\"$target\" width=\"150\" height=\"150\">"; } else { echo "Sorry, there was a problem uploading your file."; } ?> Link to comment https://forums.phpfreaks.com/topic/78126-solved-upload-bar-enhanced/#findComment-399291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.