Novahq.net Forum

Novahq.net Forum (https://novahq.net/forum/index.php)
-   phphq.Net Forums (https://novahq.net/forum/forumdisplay.php?f=277)
-   -   phUploader can erase file? (https://novahq.net/forum/showthread.php?t=41489)

chrbar 07-08-2008 06:22 PM

phUploader can erase file?
 
Hello,

This script could be perfect for us, but we need to be able to upload existing file, to replace current file by a new version (same filename)!

Is it possible?

I would like to allow to someone of our community to update a PDF file on our Web site.
This script sounds good for that, I've tried it, but I obtain an error message if the file (filename) is already in the "uploads" folder.

Do you know if it's possible to do that with this script?

Thanks,
Chris

ironmine 09-06-2008 11:47 AM

Hi, I need this exact same thing and I can't figure out how to change the script to do it. Anyone know? Probably pretty simple, but I'm not that good with PHP...

Thanks for any answers, ironmine

ironmine 09-06-2008 12:57 PM

I just figured out something that works to allow files to be overwritten. It might be the wrong way to go about enabling that, if so would someone let me know? What I did was comment out two lines of code in the script, just look for the following and add the forward slashes as I did for two lines of code after the "Check if the file..." comment/note. Do this AFTER you change the variable that causes files to be written with random names to the one that specifies using the chosen name:

// Check if the file already exists on the server..
// } Elseif(file_exists($folder.$file_name[$i])) {

// $error.= "The file: ".$_FILES['file']['name'][$i]." exists on this server, please rename your file.<br />Your file(s) were <b>not</b> uploaded.<br />";

I don't know if this causes any security issues or whatever, but I'm using the script for private use so I'm not that concerned about secuirty...

ironmine

Scott 09-06-2008 05:05 PM

you could just use the above code, comment out the line that starts with $error.="The File... and add this line right below it:
PHP Code:

unlink($folder.$file_name[$i]); 

It would look something like this:
PHP Code:

// Check if the file already exists on the server..
} Elseif(file_exists($folder.$file_name[$i])) {

// $error.= "The file: ".$_FILES['file']['name'][$i]." exists on this server, please rename your file.<br />Your file(s) were <b>not</b> uploaded.<br />";
unlink($folder.$file_name[$i]); 



All times are GMT -5. The time now is 12:58 AM.

Powered by vBulletin®