file-exists

.htaccess url-rewrite if file not exists

雨燕双飞 提交于 2019-11-27 20:27:40
I must do a little trick for a site! The idea is: if a file for a required url exists then I go to that url, doing nothing more; if a file for a required url not exists, I must go to a file.php and than do something, but NOT changing the url! example: www.mysite.com/page1.htm -> exists -> go to file page1.htm www.mysite.com/page2.htm -> NOT exists -> go to file default.php but with url "www.mysite.com/page2.htm" It's possible to do this all by .htaccess? user237419 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ /default.php [L] It is

Why does 'File.exists' return true, even though 'Files.exists' in the NIO 'Files' class returns false

大憨熊 提交于 2019-11-27 17:41:38
问题 I am trying to determine if a file exists in a network folder: // File name is "\\QWERTY\folder\dir\A123456.TXT" Path path = Paths.get("\\\\QWERTY\\folder\\dir\\A123456.TXT") Using NIO Files : Files.exists(path) == false Using File : path.toFile().exists() == true Using File seems to be the correct one according to our tests. Why does File work better than Files ? So, which is it? Can't be both! But wait, there is also Files.notExists(path) . When the network share file actually exists Files

PHP's file_exists() will not work for me?

梦想与她 提交于 2019-11-27 11:55:13
For some reason this PHP code below will not work, I can not figure it out. It is very strange, file_exists does not seem to see that the image does exist, I have checked to make sure a good file path is being inserted into the file_exists function and it is still acting up If I change file_exists to !file_exists it will return an images that exist and ones that do not exist define('SITE_PATH2', 'http://localhost/'); $noimg = SITE_PATH2. 'images/userphoto/noimagesmall.jpg'; $thumb_name = 'http://localhost/images/userphoto/1/2/2/59874a886a0356abc1_thumb9.jpg'; if (file_exists($thumb_name)) {

Check if a file exists before calling openFileInput

天大地大妈咪最大 提交于 2019-11-27 11:06:16
问题 To read a file in Android from your app's private storage area you use the function openFileInput() . My question is, is there a way to check if this file exists before calling this function? The function can throw a FileNotFoundException , but I feel like calling this and then doing something based on a try - catch is a bad practice. Using File.exist() seems like a strange thing to use also since it would require instantiating a class and I am not sure if just passing the name of the file to

PHP Rename File name if Exists Append Number to End

余生颓废 提交于 2019-11-27 10:34:54
问题 I'm trying to rename the file name of an image when it's uploaded if it exists, say if my file name is test.jpg and it already exists I want to rename it as test1.jpg and then test2.jpg and so on. With the code I've written its changing my file name like so test1.jpg and then test12.jpg any advice on fixing this would be great thank! PHP $name = $_FILES['picture']['name']; $actual_name = pathinfo($name,PATHINFO_FILENAME); $extension = pathinfo($name, PATHINFO_EXTENSION); $i = 1; while(file

check if file exists in php

老子叫甜甜 提交于 2019-11-27 03:43:22
问题 if (!(file_exists(http://mysite.com/images/thumbnail_1286954822.jpg))) { $filefound = '0'; } why won't this work? 回答1: if (!file_exists('http://mysite.com/images/thumbnail_1286954822.jpg')) { $filefound = '0'; } 回答2: The function expects a string. file_exists() does not work properly with HTTP URLs. 回答3: file_exists checks whether a file exist in the specified path or not. Syntax: file_exists ( string $filename ) Returns TRUE if the file or directory specified by filename exists; FALSE

PHP check file exists without knowing the extension

坚强是说给别人听的谎言 提交于 2019-11-27 00:28:09
问题 I need to check if a file exists but I don't know the extension. IE I would like to do: if(file_exists('./uploads/filename')): // do something endif; Of course that wont work as it has no extension. the extension will be either jpg, jpeg, png, gif Any ideas of a way of doing this without doing a loop ? 回答1: You would have to do a glob(): $result = glob ("./uploads/filename.*"); and see whether $result contains anything. 回答2: I've got the same need, and tried to use glob but this function

.htaccess url-rewrite if file not exists

六眼飞鱼酱① 提交于 2019-11-26 22:56:15
问题 I must do a little trick for a site! The idea is: if a file for a required url exists then I go to that url, doing nothing more; if a file for a required url not exists, I must go to a file.php and than do something, but NOT changing the url! example: www.mysite.com/page1.htm -> exists -> go to file page1.htm www.mysite.com/page2.htm -> NOT exists -> go to file default.php but with url "www.mysite.com/page2.htm" It's possible to do this all by .htaccess? 回答1: RewriteEngine on RewriteCond %

SSIS Script task to check if file exists in folder or not

本小妞迷上赌 提交于 2019-11-26 20:57:38
问题 I want to check to see if a file exists in a particular folder from SSIS. How can I accomplish this? 回答1: Variables: folder - string - C::\Temp\ file - string - 1.txt fileExists - boolean - False public void Main() { string folder = Dts.Variables["User::folder"].Value.ToString(); //@"C:\temp\"; string file = Dts.Variables["User::file"].Value.ToString(); //"a.txt"; string fullPath = string.Format(@"{0}\{1}", folder, file); Dts.Variables["User::fileExists"].Value = File.Exists(fullPath); Dts

How to check if a file exists from a url

不想你离开。 提交于 2019-11-26 20:05:54
I need to check if a particular file exists on a remote server. Using is_file() and file_exists() doesn't work. Any ideas how to do this quickly and easily? Amila You have to use CURL function does_url_exists($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_NOBODY, true); curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($code == 200) { $status = true; } else { $status = false; } curl_close($ch); return $status; } You don't need CURL for that... Too much overhead for just wanting to check if a file exists or not... Use PHP's get_header . $headers=get_headers($url); Then