Welcome Guest, Not a member yet? Register   Sign In
file exist check failing
#1

[eluser]bhakti.thakkar[/eluser]
hi all,
some PDF's generated by my application on click of "save and print" are directly stored on the server (remote). there is a view to see the PDF's generated till date and the user can access that PDF as and well he wants. but there are cases when the file is move to a different location or is deleted because of some reason. i want to check where the file still resides on the specified path or not.. how can i do so. i tried if( file_exists($source)) but it doesnt work. how can i do this

also tried below as i am accessing files on remote server:

Code:
if (fclose(fopen($source, "r")))

    {
        $status = "present";
    } else {
        $status = "not present";
    }
but even this is not working
Thanks
#2

[eluser]TheFuzzy0ne[/eluser]
If neither are working, then you have one of two problems.

a) Your file has incorrect permissions set, or
b) You are not looking in the right place for your file.

I would recommend you echo $source into your log file, and then SSH over to your server if you can, cd to your Web directory, and then cat the file:

cat whatever/came/from/source/variable

It will either tell you the file doesn't exist in which case it's a problem with your script. Otherwise it's probably a problem with permissions.

If you don't have SSH access to your server, you can use "getcwd()" in your script to ascertain the working directory, and then you can work from there.

Hope this helps.
#3

[eluser]bhakti.thakkar[/eluser]
Hello,
My files have the chmode 777 permissions set
Also i am looking into the right folder as the other files that are pointing to the same folder work and open well. this is only for the case where the file has been deleted or moved due to some reason. i dont want the user to see " page cannot be displayed " error
#4

[eluser]xwero[/eluser]
Did you check the $source variable to make sure it has the full filepath for the file?
#5

[eluser]TheFuzzy0ne[/eluser]
Oh, hang on. You're accessing files on a remote server? Please could you elaborate? Are they accessible via HTTP, FTP?
#6

[eluser]bhakti.thakkar[/eluser]
hello,
its via HTTP

in config.php i have defined Uploadfiles_url as
$config['UploadFiles_url'] = "http://IP_ADDRESS/UPLOADFOLDER/";


<?
foreach($query->result() as $row):
$source=$this->config->item('UploadFiles_url')."PDF_files/";

?>
<td><a >AttachedFile_VC?&gt;" target="_blank">&lt;?=$row->AttachedFile_VC;?&gt; </a></td>

Hope its clear

* [href="&lt;?=$source.$row->AttachedFile_VC" ]


and many files do get opened by the above method. but i dont want to display page not found error for those files which now do not reside on the specified path any more

Thanks
#7

[eluser]pistolPete[/eluser]
Do you have allow_url_fopen enabled?
#8

[eluser]TheFuzzy0ne[/eluser]
Is there any reason you can't use my latest creation: http://ellislab.com/forums/viewthread/106556/? If the remote server says the file can't be found, then the function returns FALSE and you can do whatever you need to do.
#9

[eluser]bhakti.thakkar[/eluser]
hi,
let me try putting the function is_working_url($url) and see whats happening. i will keep you updated on it.

Thanks
#10

[eluser]bhakti.thakkar[/eluser]
hi,

[quote author="TheFuzzy0ne" date="1235413877"]Is there any reason you can't use my latest creation: http://ellislab.com/forums/viewthread/106556/? If the remote server says the file can't be found, then the function returns FALSE and you can do whatever you need to do.[/quote]

as suggested i tried using :
Code:
function is_working_ur($url)
{
    if (substr($url, 0, 7) != 'http://' && substr($url, 0, 8) != 'https://')
    {
        $url = 'http://'.$url;
    }

    $header_arr = @get_headers($url);

    if (is_array($header_arr) && preg_grep('/HTTP\/\d+\.\d+ 200 OK/', $header_arr))
    {
        return TRUE;
    }
    
    return FALSE;
    
}

but it doesnt help as its anyways returning true for all the cases. i have done all required validations for clean urls

hope i get some help

ALSO TO BE NOTED THAT THE FILES ARE RESIDING ON THE SAME SERVER AS OF THE APPLICATION. I AM SORRY I DID A MISTAKE OF SPECIFYING THAT THE FILES ARE ON REMOTE SERVER.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB