Как да извлека картинка от дадена папка???

C++ JAVA
Post Reply
razbiva4
Нов
Нов
Posts: 22
Joined: Thu Dec 07, 2006 10:41 pm
Location: Sofia

Как да извлека картинка от дадена папка???

Post by razbiva4 » Tue Feb 27, 2007 5:09 pm

Някой може ли да ми каже как да извличам картинки от дадена папка че нещо не ми се получава :cry: ?
Който пие зло не мисли, кой не пие да му мисли..

Dido_net
Много Редовен
Много Редовен
Posts: 1569
Joined: Sat Oct 01, 2005 12:43 pm
Answers: 16
Location: Хасково

Post by Dido_net » Tue Feb 27, 2007 6:18 pm

Какво имаш в предвид? :shock:

razbiva4
Нов
Нов
Posts: 22
Joined: Thu Dec 07, 2006 10:41 pm
Location: Sofia

Post by razbiva4 » Tue Feb 27, 2007 6:21 pm

Еми имам уплоад скрипт (например) който качва картинки в папката upload. Та искам от тая папка да ми изкарва снимките в .php файл.... ако не разбрахте обяснението искайте по-ясно :lol:
Който пие зло не мисли, кой не пие да му мисли..

User avatar
jooorooo
Шаман
Шаман
Posts: 4334
Joined: Sat May 06, 2006 10:28 pm
Answers: 576
Location: I-net
Contact:

Post by jooorooo » Tue Feb 27, 2007 6:54 pm

Ето ти направо уплоад с галериика. От някъде я бях свалил. картинките са в папка images

Code: Select all

 <!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
<head>
<meta http-equiv="content-language" content="en-us">
<meta http-equiv="content-type" content="text/html; charset=windows-1251">
<title>Maaking.Com File Uploader</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<script language="JavaScript" type="text/javascript">
<!-- ;
var newwindow;
var wheight = 0, wwidth = 0;
function popimg&#40;url, title, iwidth, iheight, colour&#41; &#123;
var pwidth, pheight;

if &#40; !newwindow || newwindow.closed &#41; &#123;
pwidth=iwidth+30;
pheight=iheight+30;
newwindow=window.open&#40;'','htmlname','width=' + pwidth +',height=' +pheight + ',resizable=1,top=50,left=10'&#41;;
wheight=iheight;
wwidth=iwidth;
&#125;

if &#40;wheight!=iheight || wwidth!=iwidth &#41; &#123;
pwidth=iwidth+30;
pheight=iheight+60;
newwindow.resizeTo&#40;pwidth, pheight&#41;;
wheight=iheight;
wwidth=iwidth;
&#125;

newwindow.document.clear&#40;&#41;;
newwindow.focus&#40;&#41;;
newwindow.document.writeln&#40;'<html> <head> <title>' + title + '<\/title> <\/head> <body bgcolor= \"' + colour + '\"> <center>'&#41;;
newwindow.document.writeln&#40;'<a title="Hit to close!" href="javascript&#58;window.close&#40;&#41;;"><img src=' + url + ' border=0></a>'&#41;;
newwindow.document.writeln&#40;'<\/center> <\/body> <\/html>'&#41;;
newwindow.document.close&#40;&#41;;
newwindow.focus&#40;&#41;;
&#125;

// Routines to tidy up popup windows when page is left
// Call with an onUnload="tidy5&#40;&#41;" in body tag

function tidy5&#40;&#41; &#123;
if &#40;newwindow && !newwindow.closed&#41; &#123; newwindow.close&#40;&#41;; &#125;
&#125;

</script>

<body bgcolor="#ECF5FF" text="#3399FF" leftmargin="20" topmargin="10" marginwidth="10" marginheight="10">

<?php
/*=========================================\
Author &#58; Mohammed Ahmed&#40;M@@king&#41; \\
Version &#58; 1.1 \\
Date Created&#58; Oct 11 2004 \\
---------------------------- \\
Last Update&#58; August 21 2005 \\
---------------------------- \\
Country &#58; Palestine \\
City &#58; Gaza \\
E-mail &#58; m@maaking.com \\
MSN &#58; m@maaking.com \\
AOL-IM &#58; maa2pal \\
WWW &#58; http&#58;//www.maaking.com \\
Mobile/SMS &#58; 00972-599-622235 \\
\\
===========================================\
---Description -----------------------------------------------------
The Super Global Variable $_FILES is used in PHP 4.x.x.
$_FILES&#91;'filetoupload'&#93;&#91;'size'&#93; ==> Get the Size of the File in Bytes.
$_FILES&#91;'filetoupload'&#93;&#91;'tmp_name'&#93; ==> Returns the Temporary Name of the File.
$_FILES&#91;'filetoupload'&#93;&#91;'name'&#93; ==> Returns the Actual Name of the File.
$_FILES&#91;'filetoupload'&#93;&#91;'type'&#93; ==> Returns the Type of the File.

So if I uploaded the file 'test.doc', the $_FILES&#91;'filetoupload'&#93;&#91;'name'&#93;
would be 'phptut.doc' and $_FILES&#91;'filetoupload'&#93;&#91;'type'&#93; would be 'application/msword'.
---------------------------------------------------------------------*/

//**********************************************************************//
// $_FILES&#91;'filetoupload'&#93; is the value of //
// file field from the form. <input type="file" name="filetoupload"> //
//**********************************************************************//
################################################################################
##---------------------------1 - Setup
################################################################################
// this is the upload dir where files will go.
//Don't remove the /
//Chmod it &#40;777&#41;
$upload_dir = "images/"; //change to whatever you want.
//51200 bytes = 50KB
$size_bytes = 512000; //File Size in bytes &#40;change this value to fit your need&#41;
$extlimit = "yes"; //Do you want to limit the extensions of files uploaded &#40;yes/no&#41;
$limitedext = array&#40;".gif",".jpg",".png",".jpeg"&#41;; //Extensions you want files uploaded limited to. also you can use&#58; //array&#40;".gif",".jpg",".jpeg",".png",".txt",".nfo",".doc",".rtf",".htm",".dmg",".zip",".rar",".gz",".exe"&#41;;
################################################################################
##---------------------------2 - check for directory and writable
################################################################################
//check if the directory exists or not.
if &#40;!is_dir&#40;"$upload_dir"&#41;&#41; &#123;
die &#40;"Error&#58; The directory <b>&#40;$upload_dir&#41;</b> doesn't exist"&#41;;
&#125;
//check if the directory is writable.
if &#40;!is_writeable&#40;"$upload_dir"&#41;&#41;&#123;
die &#40;"Error&#58; The directory <b>&#40;$upload_dir&#41;</b> is NOT writable, Please CHMOD &#40;777&#41;"&#41;;
&#125;

################################################################################
##---------------------------3-1 - code begins here
################################################################################
if&#40;isset&#40;$_POST&#91;'uploadform'&#93;&#41;&#41;&#123;
// if you clicked the &#40;Upload File&#41; button. "If you submitted the form" then upload the file.
//begin of uploadform.

// $filename will hold the value of the file name submetted from the form.
$file_tmp = $_FILES&#91;'filetoupload'&#93;&#91;'tmp_name'&#93;;
$file_name = $_FILES&#91;'filetoupload'&#93;&#91;'name'&#93;;
//Get the Size of the File
$file_size = $_FILES&#91;'filetoupload'&#93;&#91;'size'&#93;;

//check if no file selected.
if &#40;!is_uploaded_file&#40;$file_tmp&#41;&#41;&#123;
echo "Error&#58; Please select a file to upload!. <br>»<a href=\"$_SERVER&#91;PHP_SELF&#93;\">back</a>";
exit&#40;&#41;; //exit the script and don't do anything else.
&#125;


//Make sure that file size is correct
if &#40;$file_size > $size_bytes&#41;&#123;
echo "Error&#58; File Too Large. File must be <b>". $size_bytes / 1024 ."</b> KB. <br>»<a href=\"$_SERVER&#91;PHP_SELF&#93;\">back</a>";
exit&#40;&#41;;
&#125;
//check file extension
$ext = strrchr&#40;$file_name,'.'&#41;;
if &#40;&#40;$extlimit == "yes"&#41; && &#40;!in_array&#40;strtolower&#40;$ext&#41;,$limitedext&#41;&#41;&#41; &#123;
echo&#40;"Error&#58; Wrong file extension. "&#41;;
exit&#40;&#41;;
&#125;


// Check if file is Already EXISTS.
if&#40;file_exists&#40;$upload_dir.$file_name&#41;&#41;&#123;
echo "Oops! The file named <b>$file_name</b> already exists. <br>»<a href=\"$_SERVER&#91;PHP_SELF&#93;\">back</a>";
exit&#40;&#41;;
&#125;

//to remove spaces from file name we have to replace it with "_".
$file_name = str_replace&#40;' ', '_', $file_name&#41;;
//Move the File to the Directory of your choice
//move_uploaded_file&#40;'filename','destination'&#41; Moves afile to a new location.
if &#40;move_uploaded_file&#40;$file_tmp,$upload_dir.$file_name&#41;&#41; &#123;
//tell the user that the file has been uploaded and make him alink.
echo "File &#40;<a href=\"$upload_dir$file_name\">$file_name</a>&#41; uploaded! <br>»<a href=\"$_SERVER&#91;PHP_SELF&#93;\">back</a>";
exit&#40;&#41;;
&#125;else&#123;
// print error if there was a problem moving file.
echo "There was a problem moving your file. <br>»<a href=\"$_SERVER&#91;PHP_SELF&#93;\">back</a>";
exit&#40;&#41;;
&#125;

################################################################################
##---------------------------3-2 - code to display the form
################################################################################
//end of if&#40;$uploadform&#41;.
// If the form has not been submitted, display it!
&#125;else&#123;
//begin of else

// get the all extensions from the array
for&#40;$i=0;$i<count&#40;$limitedext&#41;;$i++&#41;&#123;
if &#40;&#40;$i<>count&#40;$limitedext&#41;-1&#41;&#41;$commas=", ";else $commas="";
list&#40;$key,$value&#41;=each&#40;$limitedext&#41;;
$all_ext .= $value.$commas;
&#125;

//print the form
echo "<br><h3>&#58;&#58;Browse a File to Upload&#58;</h3>"
."- Allowed Extensions&#58; $all_ext</b> <br>"
."- Max File Size = ". $size_bytes / 1024 ."KB"
."<form method=\"post\" enctype=\"multipart/form-data\" action=\"$PHP_SELF\">"
."<input type=\"file\" name=\"filetoupload\"><br>"
."<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\"><br>"
."<input type=\"Submit\" name=\"uploadform\" value=\"Upload File\">"
."</form>";
&#125;//end of else

################################################################################
##---------------------Function to delete files ------------------------------##
################################################################################
function del&#40;&#41;&#123;
// if we want to insert a value inside any function we have to global it first.
global $upload_dir, $file;

//delete the file
@unlink&#40;$upload_dir."/$file"&#41;;
echo"<h3><font color=red>The File &#40;$file&#41; was deleted! <br> Please wait...</font></h3>";
echo "<meta http-equiv=Refresh content=1;url=index.php>";
&#125;

//define variable to switch between functions
if &#40; $action == del &#41;&#123;
del&#40;&#41;;
&#125;

// Here is the most interesting part.
################################################################################
##---------------------------------Added Option ------------------------------##
################################################################################
################################################################################
##---------------------View uploaded files &#40;photo gallery&#41; -------------------##
################################################################################


echo "<br><hr><center><b>Current Uploaded Files &#40;Gallery&#41;</b></center><br>";

// set number of columns for the Gallery.
$cols = 3;
// set aloop for defining columns.
$i =1;
// creating table inorder to use it for columns.
echo "<table width=100% border ='1' bordercolor='#3399FF' cellpadding='10' cellspacing='6'>
<tr>";

//open the dir where files were uploaded inside.
$opendir =opendir&#40;$upload_dir&#41;;
// create a loop and define a variable called &#40;$file&#41;
// to hold the value of file name located in the directory .
while &#40;$file = readdir&#40;$opendir&#41;&#41; &#123;
//exclude anything that doen't look like files.
if&#40;$file != '..' && $file !='.' && $file !=''&#41;&#123;
//dont't read direcories insde our directory.
if &#40;!is_dir&#40;$file&#41;&#41;&#123;

// since i am using gallery we have to get the width and hieght of photos.
$imgsize = getimagesize &#40;$upload_dir."".$file&#41;;

// lets get the file size in byte/kb/mb.
$file_size = filesize&#40;$upload_dir."".$file&#41;;

if &#40;$file_size >= 1048576&#41;&#123;
$show_filesize = number_format&#40;&#40;$file_size / 1048576&#41;,2&#41; . " MB";
&#125;elseif &#40;$file_size >= 1024&#41;&#123;
$show_filesize = number_format&#40;&#40;$file_size / 1024&#41;,2&#41; . " KB";
&#125;elseif &#40;$file_size >= 0&#41;&#123;
$show_filesize = $file_size . " bytes";
&#125;else&#123;
$show_filesize = "0 bytes";
&#125;

//Gets file modification time
$last_modified = date &#40;"F d Y H&#58;i&#58;s", filemtime&#40;$upload_dir."".$file&#41;&#41;;

//for images width.
if &#40;$imgsize&#91;0&#93; > 100&#41;&#123;
$base_img = "<img src=\"$upload_dir$file\" border=\"0\" width=\"100\">";
&#125;else&#123;
$base_img = "<img src=\"$upload_dir$file\" border=\"0\">";
&#125;
//define a variable to hold everthing that will be printed in table's columns.
$all_stuff = "File name&#58;<b> $file</b> <hr size=1>
<div style=\"width&#58; 120px; height&#58; 120px; z-index&#58; 1; float&#58; left; border&#58; 1px dotted #C0C0C0\">
<a href=\"javascript&#58;popimg&#40;'$upload_dir$file','$file', $imgsize&#91;0&#93;, $imgsize&#91;1&#93;,'white'&#41;\">
$base_img</a>
</div>
<p align=left>
Size&#58; $show_filesize<br>
Options&#58; &#91;<a title=\"Delete File\" href=\"javascript&#58;;\" onClick=\"cf=confirm&#40;'Are you sure you want to delete?'&#41;;if &#40;cf&#41;window.location='index.php?action=del&file=$file'; return false;\">Del</a>&#93;
<br>Width &#58; $imgsize&#91;0&#93; px
<br>Height &#58; $imgsize&#91;1&#93; px
<br>Date added&#58; $last_modified GMT";


//divide the loop &#40;$i&#41; and &#40;$cols&#41; if the result is integer
//then print column number 1.
if &#40;is_int&#40;$i / $cols&#41;&#41;&#123;
echo "<td align='center' valign='top' bgcolor='#F2F2F2'>$all_stuff</td></tr><tr>";
&#125;else&#123;
//else then print column number 2 etc for the next loop.
echo "<td align='center' valign='top' bgcolor='#F2F2F2'>$all_stuff</td>";
&#125;
//add only 1 for the loop &#40;$i&#41;.
$i++;
&#125;
&#125;
&#125;//end while loop
closedir&#40;$opendir&#41;;
clearstatcache&#40;&#41;;
// print the rest of table.
echo "</tr>
</table>";

//print copyright ;&#41;
echo"<p align=\"right\"><br>Script by&#58; <a href=\"http&#58;//www.maaking.com\">maaking.com</a></p>
</body>
</html>";

razbiva4
Нов
Нов
Posts: 22
Joined: Thu Dec 07, 2006 10:41 pm
Location: Sofia

Post by razbiva4 » Tue Feb 27, 2007 7:09 pm

Мерси jooorooo 8)
Който пие зло не мисли, кой не пие да му мисли..

razbiva4
Нов
Нов
Posts: 22
Joined: Thu Dec 07, 2006 10:41 pm
Location: Sofia

Post by razbiva4 » Fri Mar 02, 2007 4:41 pm

За да не права спам ше пиша тука. Имам още 1 вапрос :? Как да направя така че да ми се показват файлове само в определен формат (по точно . jpg) ???
Който пие зло не мисли, кой не пие да му мисли..

User avatar
Soul_Stealler
Web-tourist
Web-tourist
Posts: 3559
Joined: Tue Dec 20, 2005 3:52 pm
Answers: 112
Location: София
Contact:

Post by Soul_Stealler » Fri Mar 02, 2007 4:44 pm

<?php
$razshir = strrchr($files, ".") ;
$razshir = strtoupper($razshir);
if ($razshir == ".JPG" || $razshir == ".JPEG"){
/// КОДА ТИ
}
?>

Където $files е името на файла :wink:

Post Reply