Jump to content

failed to open stream: No such file or directory


momasri

Recommended Posts

Hello, this is my first post I hope you guys can help me out here, basically whats going on is I declare a variable "$diree" then I insert it in a function  but its not getting recognized, here is the code:

 

$institutea "some directory";

$dire = str_replace(" ","-",$institutea);

 

 

# SETTINGS

$max_width = 110;

$max_height = 130;

 

$per_page = 5;

$page = $_GET['page'];

 

$has_previous = false;

$has_next = false;

 

function getPictures() {

global $page, $per_page, $has_previous, $has_next;

if ( $handle = opendir($diree.'/') ) { // done changes here

$lightbox = rand();

?><table border="1"><tr><td>

<form action="pro.php" method="post">

 

 

 

<?php

echo "<ul id='pictures'>";

 

$count = 1;

$skip = $page * $per_page;

 

if ( $skip != 0 )

$has_previous = true;

 

while ( $count < $skip && ($file = readdir($handle)) !== false ) {

if ( !is_dir($file) && ($type = getPictureType($file)) != '' )

$count++;

}

$count = 1;

while ( $count < $per_page && ($file = readdir($handle)) !== false ) {

if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {

 

if ( ! is_dir($dire .'/') ) {  // done changes here

mkdir($dire .'/'); // done changes here

}

if ( ! file_exists($dire .'/'.$file) ) {

makeThumb( $file, $type );

}

 

 

echo '<li>';

echo '<img src="'.$dire .'/'.$file.'" alt="" / width="110" height="110"><br/><input type="checkbox" name="food[]" value='.$file.'>'; // done changes here

echo '</li>';

 

$count++;

 

}

}

echo '</ul>';

?>

</td></tr><tr><td><div align="center"><input type="submit" value="Add"></div></td></tr>

</tr></table></form>

<?php

while ( ($file = readdir($handle)) !== false ) {

if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {

$has_next = true;

break;

}

}

}

}

 

function getPictureType($file) {

$split = explode($dire .'/', $file);

$ext = $split[count($split) - 1];

if ( preg_match('/jpg|jpeg/i', $ext) ) {

return 'jpg';

} else if ( preg_match('/png/i', $ext) ) {

return 'png';

} else if ( preg_match('/gif/i', $ext) ) {

return 'gif';

} else {

return '';

}

}

 

function makeThumb( $file, $type ) {

global $max_width, $max_height;

if ( $type == 'jpg' ) {

$src = imagecreatefromjpeg($file);

} else if ( $type == 'png' ) {

$src = imagecreatefrompng($file);

} else if ( $type == 'gif' ) {

$src = imagecreatefromgif($file);

}

if ( ($oldW = imagesx($src)) < ($oldH = imagesy($src)) ) {

$newW = $oldW * ($max_width / $oldH);

$newH = $max_height;

} else {

$newW = $max_width;

$newH = $oldH * ($max_height / $oldW);

}

$new = imagecreatetruecolor($newW, $newH);

imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH);

if ( $type == 'jpg' ) {

imagejpeg($new, $dire .'/'.$file);

} else if ( $type == 'png' ) {

imagepng($new, $dire .'/'.$file);

} else if ( $type == 'gif' ) {

imagegif($new, $dire .'/'.$file);

}

imagedestroy($new);

imagedestroy($src);

}

?>

Link to comment
Share on other sites

Actuly this is my first line few lines of code:

 

require_once("configure.php");

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database" . mysql_error());

@mysql_select_db("$DBName") or die("Unable to select database $DBName" . mysql_error() );

$user_sql = "select institute from $DBtable order by email" ;

 

$user_result = mysql_query($user_sql) or die(mysql_error());

 

while($user_array = mysql_fetch_array($user_result))

{

 

$institutea = $user_array[institute] ;

}

 

$dire = str_replace(" ","-",$institutea);

echo "<br />" . dire;  // this shows a value

// and if I do an echo it works but if I do an echo inside the function is does not work, if I do an echo after the function it works

Link to comment
Share on other sites

sweet thanks, this solves the main problem. now I have a sub question from the above code:

 

in the Body of the page I write:

// this line displays the Pictures I have the "$dire" folder as specified in the code above

<?php getPictures(); ?>

 

 

// this line makes a Previous Page if exists

// and  makes a Next button for Next Page views if they exist

<?php
if ( $has_previous ) 
	echo '<div align="left" style="padding-left:100"><a href="?page='.($page - 1).'">← Previous Page</a></div>';

if ( $has_next )  
	echo '<div align="right" style="padding-right:100"><a href="?page='.($page + 1).'"> Next Page →</a></p>';
?>

 

// the code below gives me numbers for each page, so if the totall number of pictures per page is 5, and i have 20 pictures it gives me links  0 1 2 3 4

 

My question is How can I set my first page to be number "1"  insted of number "0" 

now I am sure the Fix for it is not in the code below, but I thought I would paste all so you can make use of this Picture Pigntaion

$directory = $dire .'/';
if (glob("$directory*.jpg") != false)
{
$filecount = count(glob("$directory*.jpg"));
echo "You have " . $filecount . " Number of Files";
echo "<br/><br/>";	
$total = $filecount / $per_page;
echo "That means you have " .$total . " Number of Pages to view";

for ($i = 0; $i <= $total; $i++)
if ($i >= 0)
{
echo '<p class="prev"> <a href="?page='.$i.'"> '.$i.' </a></p>';
}
}		
?>

Link to comment
Share on other sites

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.