Couple questions..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

OMG... DOES IT MATTER?


I ASKED TWICE HOW CAN I FIX MY OTHER PROBLEM MAYBE YOU WOULD LIKE TO DISCUSS THAT INSTEAD OF SOMETHING THAT DOESN'T MATTER?

its so small yet its causin so many problems..
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

nick2 wrote:why won't this work?

code:

Code: Select all

<?php
unlink("/" . $_COOKIE[user] . "/" . $_POST[delete]);
header("location: Http://www.slices.net/pictures.php");
?>
errror:

Warning: unlink(/mom/avatar1.jpg): No such file or directory in /home/virtual/site9/fst/var/www/html/removep.php on line 2

Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site9/fst/var/www/html/removep.php:2) in /home/virtual/site9/fst/var/www/html/removep.php on line 3
your second is a result of the first
the first means that it can't find the file. always use absolute paths. you probalby either don't realize you need to switch directories or don't switch properly.

there's a bunch of newbs lately that look like they are seekking someone to write or re-write a script for them.

try doing some debugging. instead of unlinking like you do, set it in a variable first, then echo that out. my guess is that you're not used to posix and don't realize / is the top level dir and you want to be in the user's dir wwhich would be /home/username/
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Not because it matters much perhaps, but I'm adressing the first question just to make it noted:

Code: Select all

/*
 loop dir, match 3 file ext's, if ok populate an array for later use.
 using substr() to pick the last 4 chars in the supposed file (that might be
 a directory), and use that to verify it...
*/
while (($file = readdir($dh)) !== false) {
   if (substr($file,-4) == '.jpg' or substr($file,-4) == '.gif' or substr($file,-4) == '.bmp') {
        $images[] = $file;
     }
}
Using unlink like that wont probably work as you are working on server structure rather than www-address structure.

Code: Select all

www.example.com/ = /html/JAM/www/
www.example.com/images/ = /html/JAM/www/images/
...meaning, that if you unlink something, you must use /html/JAM/www/images/ as above shows.
Note that on windows it works differently, so if you are testing at home on a local server running on win32 you need to rearrange that.
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

so is there a solution? I don't understand what u are doing with http://www.example.com = /html/etc/etc
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Hmmm

Php and webservers is actually programs on a computer, that works using the servers directory structure (among other things).

So if you go to http://www.example.com/index.html the webserver translates it into, /html/folder/whatever/foo/index.html but of course, you do not see that.

Same with PHP. When using unlink, you must be aware of that you are trying to delete a file that PHP see's as a file in a folder, on the computer.
You must provide the entire path leading to it. Meaning;

Code: Select all

/*
 Full Address: http://www.example.com/folder/script.php
 Html home directory, webserver: /html/JAM/foo/
 directory using above Full Address: /html/JAM/foo/folder/
*/
unlink('file.php');
// is in theory the same as...
unlink('/html/JAM/foo/file.php');
or taking your example code:

Code: Select all

<?php
unlink("/you/are/missing/directory/structure/here/" . $_COOKIE[user] . "/" . $_POST[delete]);
header("location: Http://www.slices.net/pictures.php");
?>
More understandable?
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

jam, he doesn't want help. if he wanted help he would have asked something in respone tomy stating he should use absolute paths.

he wants you to write it. go check the gd thread in here. gen-ik noted that too. he attacked both gen-ik and i when we asked for him to show us some code and tell us the errors so we could understand his issue and help. his response was to directly attack me and indirectly attack gen-ik.

he even states flat out that he's using this to get fully functional code after he's had a problem. not to learn by getting advice on how to fix his issues.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

I noticed also, but didn't want to belive it. I wanted to give it a shot, but the above post was my last on the subject.
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

actually I just said I was sorry in that thread.. JAM thats what i've been doing the whole time .. but in the end I finally figured it out..


thanks a bunch:

for some odd reason it just works this way any other way and it says it can't find the directory.

Code: Select all

<?php
$loc = "/home/virtual/site9/fst/var/www/html/";
unlink ($loc . $_COOKIE[user] . "/" . $_POST[delete]);
?>
<?
header("location: Http://www.slices.net/pictures.php");
?>
once again sorry. 8)
Post Reply