{"id":1995,"date":"2004-03-14T18:35:58","date_gmt":"2004-03-14T18:35:58","guid":{"rendered":"http:\/\/www.soulhuntre.com\/items\/date\/2004\/03\/14\/php-file-upload-adventure\/"},"modified":"2004-03-14T18:35:58","modified_gmt":"2004-03-14T18:35:58","slug":"php-file-upload-adventure","status":"publish","type":"post","link":"http:\/\/legacyiamsenseiken.local\/2004\/03\/14\/php-file-upload-adventure\/","title":{"rendered":"PHP file upload adventure…"},"content":{"rendered":"
For the project I am working on for Client A I have had to tackle file uploading via the browser in PHP<\/a>. I had purchased a Dreamweaver<\/a> extension a while back to handle this sort of thing, but it turns out to be inadequate for my needs in this case. I certainly have gotten the value from it, but it just isn’t flexible enough any more. So here is a little code snippet and some links that helped me out.<\/p>\n <\/p>\n I am not sure what I am going to do with the result, I may release it publicly or I might make it commercial. Anyway, here is a snippet that might help you out if you are looking for a way to make a unique filename in PHP.<\/p>\n Assuming that:<\/b><\/p>\n Then you can do this:<\/b><\/p>\n ed. note: I altered this code for posting, so check it for errors before you use it in anything important. It’s at your own risk, if it wipes your data or turns you into a [[wp:zombie]] don’t blame me.<\/em><\/p>\n<\/blockquote>\n function make_unique_name<\/strong>( $name, $ext, $path, $iterations ){ These links were particularly helpful:<\/b><\/p>\n For the project I am working on for Client A I have had to tackle file uploading via the browser in PHP. I had purchased a Dreamweaver extension a while back to handle this sort of thing, but it turns out to be inadequate for my needs in this case. I certainly have gotten the […]<\/p>\n","protected":false},"author":3,"featured_media":56233,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"footnotes":""},"categories":[278],"tags":[],"_links":{"self":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/posts\/1995"}],"collection":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/comments?post=1995"}],"version-history":[{"count":0,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/posts\/1995\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/media\/56233"}],"wp:attachment":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/media?parent=1995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/categories?post=1995"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/tags?post=1995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\n
\n
\n
for( $i = 0; $i < $iterations; $i++ ) {
$testname = uniqid( $name . “_” );
$testfullname = $testname . “.” . $ext;
if( !file_exists( $path . “\/” . $testfullname ) ){
return $testfullname;
}
}
return “”;
}<\/p>\n<\/blockquote>\n\n