Jump to content

write and append filename to text file if not exist


acctman

Recommended Posts

i'm using the code below to display images, i'd like for it to write the file name to a text filename ($mid.'-'.$iid.'.jpg') if it does not exist, how can I do that and have it append each time.

 

session_start();
$userid = $_SESSION['userid'];
if ($_GET['sec'] != 3 && $userid == '') {
header("Location: http://www.main.com");
exit;
}
ob_start();

if (isset($_GET['mid']) && isset($_GET['iid']) && isset($_GET['idat']) && isset($_GET['sec'])) {
$mid = $_GET['mid'];
$iid = $_GET['iid'];
$date = $_GET['idat'];

if ($_GET['sec'] == 1) { $type = "imgPvt";
$allowed = 0;
	if (intval($_SESSION['userid']) > 0) {
		if (mysql_num_rows(mysql_query("select p_id from rate_private where p_from='$mid' and p_to='" .$_SESSION['userid']. "'")) > 0 || $mid == $_SESSION['userid'] || $_SESSION['userid'] == '39') {
        $allowed = 1;
		} elseif ($allowed == 0 && $_GET['sec'] == 1) {
			header("Location: http://www.main.com");
			exit;
		}
	} 
}	
if ($_GET['sec'] == 2) { $type = "imgExp"; } 
if ($_GET['sec'] == 3) { $type = "imgPub"; }			
  $im = @imagecreatefromjpeg('../imgs/'.$date.'/'.$mid.'/'.$type.'/'.($_GET['tmb']==1 ? 'imgTmb/' : '').$mid.'-'.$iid.'.jpg');
  	if(!$im) {
  		exit();
  	}
header("Content-type: image/jpeg");	
imagejpeg($im);
imagedestroy($im);					
}
$buf = ob_get_contents();
ob_end_clean();
print $buf;

Link to comment
Share on other sites

shud be rread wwrite append.

u can add a + which sets it as both read/write.

 

r read only, file pointer at start

r+ read/write, file pointer at start

w write (kill original file), file pointer at start

w+ read/write (kill original file), file pointer at start

a append, file pointer at end

a+ append/read, file pointer at end

 

and ya can add to the aboce to put it in binary mode  (no cr/lf translation)

 

 

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.