PHP chdir() | |
|
|
Junior Mitglied Beiträge: 2 Registriert: 21.02.2008 | Hello,
I am trying to change directories within a php snippet where people can upload pictures to my website. If I use the chdir() command, I recieve the error:
Warning: chdir() [function.chdir]: No such file or directory (errno 2) in /home/nicollc/public_html/wedding/upload.php on line 28
why is this?
Here is a snippet of code to help you understand:
for($x=1; $x<=$uploadNeed; $x++){
$file_name = $_FILES['uploadFile'. $x]['name'];
if (empty($file_name)) {
echo "<h3>ERROR!</h3>"; ?>
<p class="text">You didn't specify which file(s) you would like to upload!</p>
<p class="text"><a href="javascript:history.back()">Go back and try again!</a></p>
<?php include("footer.php");
die();
} else {
chdir("$name");
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","", $file_name);
$file_name = strtolower($file_name);
if (file_exists($file_name)) { ?>
<p class="text"><?php echo $file_name; ?> already exists. Please use a different filename if it is a different photo.</p>
<?php } elseif (!file_exists($file_name)) {
list($file, $ext) = split('[.]', $file_name);
if ($ext == "jpg") {
$copy = copy($_FILES['uploadFile'.$x]['tmp_name'], $file_name);
} else { ?>
<p class="text"><?php echo $file_name; ?> cannot be uploaded as it has the wrong format.
Please ensure that it has the correct file extension.</p>
<?php }
}
chdir("uploads");
// check if successfully copied
if ($copy) {
$entrydate = date("Y-m-d H:i:s");
$insert = mysql_query("INSERT INTO uploads (Owner,filename,datetime) VALUES ('$name','$file_name','$entrydate')") or die(mysql_error());
if (mysql_insert_id()) { ?>
<p class="text"><?php echo $file_name ?> has been sucessfully uploaded!</p>
<?php }
}
}
} // end of loop
Thanks
Jason |
|
|
|
|
|
Re: PHP chdir() | |
|
|
Administrator Beiträge: 689 Registriert: 17.11.2003 | Hello,
you can't change to a directory which doesn't exist. Please check your parameter and the current directory.
| Zitat | | | Warning: chdir() [function.chdir]: No such file or directory (errno 2) in /home/nicollc/public_html/wedding/upload.php on line 28 |
|
|
|
|
|
|
Re: PHP chdir() | |
|
|
Junior Mitglied Beiträge: 2 Registriert: 21.02.2008 | | Zitat | | Original erstellt: 2008-02-21 22:57 von Rubas
Hello,
you can't change to a directory which doesn't exist. Please check your parameter and the current directory.
|
The directories have been created, I was just showing part of the the script which was showing the error message. |
|
|
|
|
|
Re: PHP chdir() | |
|
|
Administrator Beiträge: 689 Registriert: 17.11.2003 | We can't help you here with your coding problems but check your current directory (getcw). The error message doesn't lie .. |
|
|
|
|
|