-3

i am new to php. now i want to know these

1) how i can get url path upto last folder suppose url is http://www.abc.com/xyz/aaa/bbb/login.php?id=23 i want to take upto http://www.abc.com/xyz/aaa/bbb

2)How i can give cryptic path to an image while displaying from database

<img src="<?php echo $path;?>" /> how i can give this $path cryptic one

3)how i can send mail daily at 11.pm

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
jaya
  • 59
  • 8
  • 1) Use .htaccess url rewrite, 2) I didn't understood what's cryptic, 3) Cron Job... – Mr. Alien Nov 14 '12 at 10:55
  • What is a 'cryptic path' for you? – arkascha Nov 14 '12 at 10:55
  • For 1.): you want to be able to call login.php by the shorter url, or do you want to extract that shorter url inside your php script for other purposes? – arkascha Nov 14 '12 at 10:57
  • @arkascha thanks for reply. cryptic path means only to not able to understand path – jaya Nov 14 '12 at 11:00
  • @Mr.Alien thanks for reply. cryptic path means only to not able to understand path – jaya Nov 14 '12 at 11:00
  • That makes little sense, sorry. If the path is used to display (reference) an img via a url then the image can be retrieved using that url. No one is interested in how that path looks like. – arkascha Nov 14 '12 at 11:01
  • @jaya than say suppose you are just saving the file name say `abc.png` inside `images` folder than use php like `` – Mr. Alien Nov 14 '12 at 11:01
  • @Mr.Alien Actually i want to send images in mail. Suppose these are important images, To make authentication how i can give encrypted path to image. – jaya Nov 14 '12 at 11:04
  • If you attach an image to an email you do not specify a path. The image is contained inside that message. Referecing images inside a html mail by an url is a bad habit anyway, don't. Usage of html emails are the primary cause of system infections these days. Well, html emails and stupid systems being vulnerable at millions of points. – arkascha Nov 14 '12 at 11:05
  • For question number 2 this might help you: http://stackoverflow.com/questions/35879/base64-encoding-image – Badea Sorin Nov 14 '12 at 11:08
  • @arkascha then without html. how we can send email with images? – jaya Nov 14 '12 at 11:09
  • There are ready-to-use solutions for email attachments available for php. Basically they construct a 'special' body and send it as email message. The only difference to a 'normal' email is that the body is 'multi-part-encoded', so consists of multiple parts. You could do this by hand, but I advise to use an existing solution. – arkascha Nov 14 '12 at 11:16
  • @BadeaSorin: the OP wants to obfuscate the path (the url), not encode the content. – arkascha Nov 14 '12 at 11:17
  • Again the question for nr. 2: waht good should it do to obfuscate a url reference to an image? The iamge has to be referenced by the url. Either this works or not. If it works, then everyone can retrieve the image. Where is the point in obfuscation here? – arkascha Nov 14 '12 at 11:19
  • @arkascha he doesn't want that the real path to be seen ... so don't use a path.it's a very simple solution :) – Badea Sorin Nov 14 '12 at 11:19
  • @BadeaSorin: but when the OP embeds the image to an email (as attachment) as opposed to referencing it by a url, then no path is used anyway. Why should he manually base64 encode the content, he has to use a mail class anyway which will do that for him. – arkascha Nov 14 '12 at 11:23

1 Answers1

1

Let's start to collect a few answers. More might follow if you can give meaningful answers to the questions in the comments above:


Question 1: Most likely this is what you want to do:

substr($url, 0, -strlen(strrchr($url,'/')))

Alternatively:

dirname(sprintf('http://%s%s', $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']))

Question 2: There is little sense in obfuscating the path used inside a url to reference an image published somewhere: the url has to reference the image to enable anyone to see the image. For this to work the location of the image must be exposed by the url, so what is the point in that obfuscation? The obfuscated url references the image, however it looks. And everyone can use that url to retrieve the image.


Question 3: You configure a crontab entry on system level that is run daily at 11pm. That job calls something like wget http://localhost/myapp/sendmail.php. That script sendmail.php collects the required data and sends an email.

arkascha
  • 41,620
  • 7
  • 58
  • 90
  • Crontab? can you guide me to know about crontab? – jaya Nov 14 '12 at 11:07
  • What about asking google what a 'crontab' is? – arkascha Nov 14 '12 at 11:09
  • yes i got information from http://www.pantz.org/software/cron/croninfo.html thanks – jaya Nov 14 '12 at 11:12
  • Yep, that's it. Every decent system has something like this already installed. You just have to learn how to use it. I suggest you read the manpages of `cron` and `crontab` or consult a 'HowTo'. – arkascha Nov 14 '12 at 11:21
  • if i use "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; just giving total url with present executable file also. is there is no other way without using substr – jaya Nov 14 '12 at 11:22
  • I added an alternative for this. – arkascha Nov 14 '12 at 11:26