Problem in uploading the already uploaded file with duplicate name

php_issue

#1

Hi,
I am facing some problems while doing this programming task in my project. When I upload any file from browser using "Admin" account. Then file uploaded successfully and I can see this file from browser also. Similarly When I check the path "/var/www/owncloud/data/admin/files/myfile" then my file is also present there. Fine....
Now important thing is that I made some changes in that file. Mean to say I go to the path and made some changes in that file and save it with new name in same path where currently uploaded file is present.
What I want to achieve?
I just want to see this updated file in that path rather than original one. Mean I want to delete the original file. But I am not being shown the new updated file from the browser.
How can I do this?

Thanks


#2

You mean making changes directly into the /var/www/owncloud/data folder on the system?


#3

Hi,
Thanks for reply,

Directly changes means if we make some amendments for the benefit of user, then we need to re-upload the updated file from the "/var/www/owncloud/data ".

Thanks


#4

Hi,

this doesn't answer my question above. Do you go into the /var/www/owncloud/data folder and make modifications on the files there?


#5

Hi,
Actually m doing this programmaticaly. We write the following code in 'upload.php' file, when a file is uploaded, then at that time according to following code we first go (not physically, rather through programming) in the database of logged in user, and then made some changes in that file according to our desired situation(discussed already). We achieved this task successfully and a new file is also created successfully. The code is give below:

$UNAME=\OC_User::getUser();
/var/www/owncloud/data/$UNAME/files/uploadedfiles

For example:
user upload a file with name "abc", and file saved to user database as ownCloud does, then according to above code we go to the path of user database, and made some changes and new updated file is created in that data folder "/var/www/owncloud/data/$UNAME/files/newfile"
.
Now when I am seeing in the browser I am only original file "abc", I need only to show the "newfile",

How to upload "newfile" on the same upload action called on uploading the original file??


#6

My understanding of how Owncloud works is that you should not modify files directly (outside of the interface) as the file's metadata stored in the db won't get updated.

Can't you just make the changes to the file and then reupload it through Owncloud's webdav interface?


#7

Thanks for response,
In my case, it is necessary to make new file, so that's why I am doing this.
If I deleted my original file, that will complete my 20 % task.
But how can I re-upload new updated file from already called upload action?


#8

You can use WebDAV for the task, you can run a file scan after the action or you can do it inside an ownCloud App (in which case you would also use WebDAV endpoint).


#9

If you use Webdav then there is no need for a file scan (relying on file scan is a bad idea in general).

If you're programming an ownCloud app in PHP, then use the ownCloud filesystem APIs: \OC::$server->getUserFolder($userId) which gives you an instance of https://doc.owncloud.org/api/classes/OCP.Files.Folder.html.

\OC::$sevrer->getUserFolder($userId)->get($pathToParentFolderOfNewFile)->newFile()->putContent($data) (see https://doc.owncloud.org/api/classes/OCP.Files.File.html#method_putContent)

You can also replace putContent with fopen if you need to stream instead.

Hope this helps.


#10

Hi, I have tried to find out a complete example to use WebDAV, but I didn't find, Please suggest me example.

Thanks


#11

Hi, Please refer me towards exact point. I know that there is a piece of code need to be add up in "upload.php" file. But don''t know what is the code and don''t know where to write the code in uplaod.php file. Let''s suppose the file is present in the data folder,
$file=/var/www/ownCloud/data/admin/files/fileB

Now what is the code to upload this file, (keeping in mind that in the same folder there is fileA, so need to delete fileA and replace with fileB). Important thing is that the upload event is already called to upload fileA so on the same action we have to write the code to replace fileA with fileB.

Hope, now I have completed my full statement now.

Thanks