Jump to content

Recommended Posts

Hello all:

 

I have this script that uploads a file. It sends the file to a subdirectory, but if the subdirectory doesn't exist then it creates it.  Right now I am trying to create a link to this file on the page in which it corresponds to (in my case this would be parts, so in my directory(secure/parts) it creates a sudirectory for part number 1(secure/parts/0001) Here is the code:

 

// You don't really need basename() here, the name only contains the filename (with extension) (I think)
$target = basename($_FILES['uploaded']['name']);

// Assuming $fileDest is the base directory for your files
// AND Assuming it already has the / on the end of it
$dest = $fileDest . $partNumber . '/';

// Make the PartNumber directory if it is not already there
if (!is_dir($dest)) {
  mkdir ($dest,  $mode = 0777, $recursive = false);
}

// Move the uploaded file
if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $dest . $target ))
{
  echo "File uploaded!";
} else {
  $errMsg .= 'An unexpected error has occured.  Please try again and contact the Information Management Systems Administrators if the problem persists.';
}

}
//$secureLoc = '/sites/secure/parts/';
	$dest = $fileDest   . $partNumber;
	$handle = opendir($dest . '/'); 
    
    
    /* This is the correct way to loop over the directory. */
    while (false !== ($file = readdir($handle))) {
    if(!is_dir($dest . '/' . $file)){
	echo "$dest/$file<br>";
}
    	

    
    }
closedir($handle);

Ok so now the way I want this to work is I want to check the directory and tell me what is there which works fine if there has been an upload, but if not I get these nasty error messages.

Warning: opendir(/usr/local/apache/sites/secure/parts/00003/) [function.opendir]: failed to open dir: No such file or directory in /var/www/dev.neoterichovercraft.com/neoteric/code/inventory/upload.php on line 84

 

Warning: readdir(): supplied argument is not a valid Directory resource in /var/www/dev.neoterichovercraft.com/neoteric/code/inventory/upload.php on line 88

 

Warning: closedir(): supplied argument is not a valid Directory resource in /var/www/dev.neoterichovercraft.com/neoteric/code/inventory/upload.php on line 96

 

Can anyone tell me what I am missing n where to find it?

Link to comment
https://forums.phpfreaks.com/topic/184461-directory-help-please/
Share on other sites

Well, the destination (directory) variable is based on what was uploaded, so if nothign was uploaded I assume that the directory wouldn't be made. You can check if the directory exists with file_exists()

if (file_exists($my_dir_to_check)){
//do directory showing stuff
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.