|
File name append when already present
Last post 11-30-2012, 6:32 AM by Kenneth. 8 replies.
-
11-18-2012, 12:19 PM |
-
mtimmons
-
-
-
Joined on 11-13-2012
-
-
Posts 16
-
-
|
File name append when already present
I was doing some mobile testing this weekend .. uploading images form my iOS device. Greatness. But, when a file already exists with the same name, the newly uploaded file never appears. If a file is uploaded with the same name as one present, is / could there be a way to just append "_1 / _2" the file name? This would be nice!
|
|
-
11-19-2012, 6:03 AM |
-
Kenneth
-
-
-
Joined on 02-13-2008
-
-
Posts 3,886
-
-
|
Re: File name append when already present
Hi mtimmons, I suggest you use method "CopyTo" to handle the upload file store location and the file name, then before you save the upload file, you can check the file name first and save it as a new name if exists. Below is the example which shows you how to use method "CopyTo" to handle the upload file. - <?php require_once "phpuploader/include_phpuploader.php" ?>
- <?php session_start(); ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>
- example
- </title>
- </head>
- <body>
-
- <form id="form1" method="POST">
- <?php
- $uploader=new PhpUploader();
- $uploader->MaxSizeKB=10240;
- $uploader->Name="myuploader";
- $uploader->InsertText="Select multiple files (Max 10M)";
- $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.txt,*.zip,*.rar";
- $uploader->MultipleFilesUpload=true;
- $uploader->Render();
-
- ?>
-
- </form>
-
-
- <?php
- $fileguidlist=@$_POST["myuploader"];
- if($fileguidlist)
- {
- $guidlist=explode("/",$fileguidlist);
- foreach($guidlist as $fileguid)
- {
-
-
- $mvcfile=$uploader->GetUploadedFile($fileguid);
- if($mvcfile)
- {
- $mvcfile->CopyTo("D:/sites/phpuploader/test/".$mvcfile->FileName);
- }
- }
-
- }
- ?>
-
- </div>
- </body>
- </html>
Regards, Ken
|
|
-
11-27-2012, 4:50 PM |
-
mtimmons
-
-
-
Joined on 11-13-2012
-
-
Posts 16
-
-
|
Re: File name append when already present
I have not had much luck implementing this.. any more direction? my code fromt the page where my uploader is.. <div class="demo" id="uploaderDiv" style="display:none;"> <h1>Selecting multiple files for upload</h1> <h2><p>You Can select multiple files and upload multiple files at once.</p> <form id="form1" method="POST"> <?php $uploader=new PhpUploader(); $uploader->MaxSizeKB=2150400; $uploader->Name="myuploader"; $uploader->MultipleFilesUpload=true; if ($dir=="../../") { $uploader->SaveDirectory="/FTP2/WebDisk/Uploaded_Files/"; $uploader->InsertText="<br><br>CLICK TO UPLOAD FILE(S)<br>* Max 2 GB *<br><br>Goes to the 'Uploaded Files' Folder.<br><br>"; } else { $uploader->SaveDirectory=$dir; $uploader->InsertText="<br><br>CLICK TO UPLOAD FILE(S)<br>* Max 2 GB *<br><br>Goes to the currently open Folder.<br><br>"; } $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.bmp,*psd,*.tiff,*.tga,*.ind,*.ils,*.eps,*.txt,*.ptf,*.zip,*.rar,*.mp3,*.wav,*.bwf,*.aif,*.m4a,*.omf,*.mov,*.m4v,*.mp4,*m4r,*,sd2,*.caf,*.alac,*.pdf"; $uploader->Render(); ?> </form> <?php $fileguidlist=@$_POST["myuploader"]; if($fileguidlist) { $guidlist=explode("/",$fileguidlist); foreach($guidlist as $fileguid) { //get the uploaded file based on GUID $mvcfile=$uploader->GetUploadedFile($fileguid); if($mvcfile) { $mvcfile->CopyTo("/FTP2/WebDisk/Uploaded_Files/test/".$mvcfile->FileName); } } } ?>
|
|
-
11-28-2012, 6:41 AM |
-
Kenneth
-
-
-
Joined on 02-13-2008
-
-
Posts 3,886
-
-
|
Re: File name append when already present
Hi mtimmons, 1. Do not use "SaveDirectory" to store the upload file, I provided the new method "CopyTo" to handle the upload file store location. 2. $mvcfile->FileName is the original file name. In your requirement, you need to change it if has the same name file, so please wire your own code to check if the file exists, then save as a new name. if(file exists) { $mvcfile->CopyTo("/FTP2/WebDisk/Uploaded_Files/test/".NewFileName); } else { $mvcfile->CopyTo("/FTP2/WebDisk/Uploaded_Files/test/".$mvcfile->FileName); } Regards, ken
|
|
-
11-28-2012, 7:35 PM |
-
mtimmons
-
-
-
Joined on 11-13-2012
-
-
Posts 16
-
-
|
Re: File name append when already present
Ok, I put in sode code with a little time stamp to do the job. Question however, Is there a way to NOT use get? Right now I use this code on a Div that I unhide on a page to upload: - <div class="demo" id="uploaderDiv" style="display:none;">
- <h1>Selecting multiple files for upload</h1>
- <h2><p>You Can select multiple files and upload multiple files at once.</p>
- <?php
-
- $uploader=new PhpUploader();
- $uploader->MaxSizeKB=2150400;
- $uploader->Name="myuploader";
- $uploader->MultipleFilesUpload=true;
-
- $uploader->SaveDirectory="/FTP2/WebDisk/Uploaded_Files/";
- $uploader->InsertText="<br><br>CLICK TO UPLOAD FILE(S)<br>* Max 2 GB *<br><br>Goes to the 'Uploaded Files' Folder.<br><br>";
-
- $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif";
- $uploader->Render();
-
- ?>
-
- <ol id="filelist" align="left">
- </ol>
- <input type="button" name="answer" value="Close" onclick="fadeTrans('uploaderDiv')" style="width:100;" />
- </div>
However, with code provided, you were using a form to PUSH to info. Is it possible to do it without a form like I am above: New code: - <div class="demo" id="uploaderDiv" style="display:none;">
- <h1>Selecting multiple files for upload</h1>
- <h2><p>You Can select multiple files and upload multiple files at once.</p>
-
- <?php
-
- $uploader=new PhpUploader();
- $uploader->MaxSizeKB=2150400;
- $uploader->Name="myuploader";
- $uploader->MultipleFilesUpload=true;
-
- {
- $uploader->InsertText="<br><br>CLICK TO UPLOAD FILE(S)<br>* Max 2 GB *<br><br>Goes to the currently open Folder.<br><br>";
-
- }
- $uploader->AllowedFileExtensions="*.jpg,*.png,*.pdf";
- $uploader->Render();
-
- $fileguidlist=@$_POST["myuploader"];
- if($fileguidlist)
- {
- $guidlist=explode("/",$fileguidlist);
- foreach($guidlist as $fileguid)
- {
-
-
- $mvcfile=$uploader->GetUploadedFile($fileguid);
- if($mvcfile)
- {
- $path="/FTP2/WebDisk/Uploaded_Files/test/";
- $currentfilename=$mvcfile->FileName;
- $time=date('H:i:s').'_';
- if(file_exists($path.$currentfilename))
- {
- $mvcfile->CopyTo($path.$time.$currentfilename);
- }
- else
- {
- $mvcfile->CopyTo($path.$currentfilename);
- }
-
-
-
- }
- }
-
- }
- ?>
- <ol id="filelist" align="left">
- </ol>
- <input type="button" name="answer" value="Close" onclick="fadeTrans('uploaderDiv')" style="width:100;" />
-
- </div>
|
|
-
11-29-2012, 6:07 AM |
-
Kenneth
-
-
-
Joined on 02-13-2008
-
-
Posts 3,886
-
-
|
Re: File name append when already present
Hi mtimmons, For now can not achieve it without the form. Regards, Ken
|
|
-
11-29-2012, 6:32 PM |
-
mtimmons
-
-
-
Joined on 11-13-2012
-
-
Posts 16
-
-
|
Re: File name append when already present
Thanks. I reworked my implmentation to allow the form to work. The uploader is now on its own page.... Anyway, Now I have lost the print out for showing the upload status and completion via the ajax handler. Any suggestions? Here is the code now (I am not showing the ajaz-mutiple file function because is conflicst) - <html>
- <head>
-
- <link href="demo.css" rel="stylesheet" type="text/css" />
- </head>
-
- <body>
-
- <?php require_once "phpuploader/include_phpuploader.php" ?>
- <?php session_start(); ?>
-
- <h1>Selecting multiple files for upload</h1>
- <h2><p>You Can select multiple files and upload multiple files at once.</p>
- <h2><p align =center"><a href="mailto:post.admin@fellowshipchurch.com?Subject=Upload%20Support" style='color:white; size=15' col ><br>Email support.</a></p>
- <form id="form1" method="POST">
-
- <?php
- ob_start();
- include 'index.php';
- ob_end_clean();
- $dir=$_SESSION['phpuploader_dir'];
-
- $uploader=new PhpUploader();
- $uploader->MaxSizeKB=2150400;
- $uploader->Name="myuploader";
- $uploader->MultipleFilesUpload=true;
-
- if ($dir=="../../")
- {
- $uploader->InsertText="<br><br>CLICK TO UPLOAD FILE(S)<br>* Max 2 GB *<br><br>Goes to the 'Uploaded Files' Folder.<br><br>";
- $path="/FTP2/WebDisk/Uploaded_Files/test/";
- }
- else
- {
- $uploader->InsertText="<br><br>CLICK TO UPLOAD FILE(S)<br>* Max 2 GB *<br><br>Goes to the currently open Folder.<br><br>";
- $path=$dir;
- }
- $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.bmp,*psd,*.tiff,*.tga,*.ind,*.ils,*.eps,*.txt,*.ptf,*.zip,*.rar,*.mp3,*.wav,*.bwf,*.aif,*.m4a,*.omf,*.mov,*.m4v,*.mp4,*m4r,*,sd2,*.caf,*.alac,*.pdf";
- $uploader->Render();
-
- ?>
- </form>
- <?php
- $fileguidlist=@$_POST["myuploader"];
- if($fileguidlist)
- {
- $guidlist=explode("/",$fileguidlist);
- foreach($guidlist as $fileguid)
- {
-
-
- $mvcfile=$uploader->GetUploadedFile($fileguid);
- if($mvcfile)
- {
-
- $currentfilename=$mvcfile->FileName;
- $time=date('H:i:s').'_';
- if(file_exists($path.$currentfilename))
- {
-
- $mvcfile->CopyTo($path.$time.$currentfilename);
- }
- else
- {
- $mvcfile->CopyTo($path.$currentfilename);
- }
-
- }
- }
-
- }
- ?>
- <ol id="filelist" align="left">
- </ol>
-
-
-
-
- </div>
|
|
-
11-29-2012, 7:04 PM |
-
mtimmons
-
-
-
Joined on 11-13-2012
-
-
Posts 16
-
-
|
Re: File name append when already present
I tried to add: - <script type='text/javascript'>
- function CuteWebUI_AjaxUploader_OnTaskComplete(task)
- {
- var div=document.createElement("DIV");
- div.innerHTML=task.FileName + " is uploaded!";
- document.body.appendChild(div);
- }
- </script>
But, the problem is that page refreshes itself after the upload.
|
|
-
11-30-2012, 6:32 AM |
-
Kenneth
-
-
-
Joined on 02-13-2008
-
-
Posts 3,886
-
-
|
Re: File name append when already present
Hi mtimmons, The post back is necessary because the control needs to send the upload data to the server. You can handle the upload start manually, like example http://phpfileuploader.com/demo/form-manualstart.php Regards, Ken
|
|
|
|
|