|
查看: 1518|回复: 35
|
warning : filesize() / filemtime()
[复制链接]
|
|
|
我把照片Upload进一个directory了,可是怎样display出来呢?
就好象你Upload了一张照片它会自动display出来给你check酱紫..
<?PHP
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 200000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
[ 本帖最后由 creme 于 4-4-2008 09:14 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 30-3-2008 02:48 PM
|
显示全部楼层
顶下..
我只会 <img src = ......> </img>  |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 30-3-2008 03:30 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 30-3-2008 04:02 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 30-3-2008 04:14 PM
|
显示全部楼层
如果我是upload到 "FILEUPLOAD" 的 folder
是不是
echo "<p><img src=fileupload/******** height=127 border=1>";
可是那个*******应该写什么呢? |
|
|
|
|
|
|
|
|
|
|
发表于 30-3-2008 04:14 PM
|
显示全部楼层
Upload以后,你必须把Path,及filename储存起来,以后才可以refer back。
假设你所有Upload的Photo都收在 "upload" 的Folder,那你只要 Insert $_FILES["file"]["name"] 进Database。
然后Query Filename出来(假设你assign to $filename)。
<?php
echo "<img src='admin/'" . $filename . "'></img>';
?>
大概是酱子。。。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 30-3-2008 07:57 PM
|
显示全部楼层
嗯,对不起我菜鸟>..
是这样吗?
echo "<img src='upload/'" .$_FILES["file"]["name"] . "'></img>"; |
|
|
|
|
|
|
|
|
|
|
发表于 31-3-2008 11:40 AM
|
显示全部楼层
Correct, correct, correct.....
套用Mr. Lingam 的名句 |
|
|
|
|
|
|
|
|
|
|
发表于 31-3-2008 11:49 AM
|
显示全部楼层
其实你可以检查photo的URL对不对的。如果照片显示不出来,就在Photo上,Right-click, property, 看photo的address是什么咯。
通常你必须将address (也就是src)弄成:
"http://localhost/youDirectory/admin/XXX.jpg"....
大概是酱咯。。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 31-3-2008 11:36 PM
|
显示全部楼层
我成功了!我成功了!我成功了!!!
阿哈哈哈哈!!!!
开心到!!!!!!!!!!!!!!!!!!
谢谢各位!!!!
阿哈阿哈哈~~~~!!!!! |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 4-4-2008 09:13 PM
|
显示全部楼层
是想看我folder里照片的资料,可是出现这个,是什么意思呢?
Warning: filesize() [function.filesize]: stat failed for DSC02076.JPG in C:\xampp\htdocs\sc\browse.php on line 19
Warning: filemtime() [function.filemtime]: stat failed for DSC02076.JPG in C:\xampp\htdocs\sc\browse.php on line 20
我的Line 19—20
$fs=filesize($file); //line 19
$moddate=date('F j, Y',filemtime($file)); //line 20
echo ' <tr>
<td>'.$file.'</td>
<td>'.$fs. ' bytes</td>
<td>'.$moddate.'</td>';
[ 本帖最后由 creme 于 4-4-2008 09:29 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 4-4-2008 10:46 PM
|
显示全部楼层
应该是你的File Path 不对。我刚刚试了一下,如果没有这个File,是会出现这个Message的。
echo你的$file来看看? |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 5-4-2008 03:35 AM
|
显示全部楼层
怎么说呢?可是他有result哦?
这是display 出来的整页 --borneo1.jpg 是我folder里的照片,他就是没有filesize和 last modified 的资料,也不懂前面那两个是什么来的....
Current directory is upload/
Warning: filesize() [function.filesize]: stat failed for borneo1.jpg in C:\xampp\htdocs\sc\browse.php on line 19
Warning: filemtime() [function.filemtime]: stat failed for borneo1.jpg in C:\xampp\htdocs\sc\browse.php on line 20
File Name File Size Last Modified
. 16384 bytes April 4, 2008
.. 4096 bytes March 26, 2008
borneo1.jpg bytes January 1, 1970
这是整个coding
<?php
$current_dir = 'upload/';
$dir = opendir($current_dir);
echo "Current directory is <b>$current_dir</b><br />";
echo' <table width="100%" border="0" cellspacing="1">
<tr>
<td width="34%"><b>File Name</b> </td>
<td width="26%"> <b>File Size </b></td>
<td width="40%"><b>Last Modified</b> </td>
</tr>';
while ($file = readdir($dir))
{
$fs=filesize($file);
$moddate=date('F j, Y',filemtime($file));
echo ' <tr>
<td>'.$file.'</td>
<td>'.$fs. ' bytes</td>
<td>'.$moddate.'</td>';
}
closedir($dir);
?>
[ 本帖最后由 creme 于 5-4-2008 03:36 AM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 5-4-2008 01:11 PM
|
显示全部楼层
试试将整个path加在filename前面。刚才我试了一下,Ok。(我的PHP document root和你的可能不一样。请改成你的Path)。
<?php
$current_dir = 'upload/';
$dir = opendir($current_dir);
echo "Current directory is <b>$current_dir</b><br />";
echo' <table width="100%" border="0" cellspacing="1">
<tr>
<td width="34%"><b>File Name</b> </td>
<td width="26%"> <b>File Size </b></td>
<td width="40%"><b>Last Modified</b> </td>
</tr>';
while ($file = readdir($dir))
{
$file = "D:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\projectname\\" . $file;
$fs=filesize($file);
$moddate=date('F j, Y',filemtime($file));
echo ' <tr>
<td>'.$file.'</td>
<td>'.$fs. ' bytes</td>
<td>'.$moddate.'</td>';
}
closedir($dir);
?> |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 5-4-2008 02:50 PM
|
显示全部楼层
哈哈哈,可以了可以了,真是厉害
可是,前面还是会有两个莫名其妙的资料,不过没关系啦
其实$file具体上市有什么用途的?
就是用来query而已吗? |
|
|
|
|
|
|
|
|
|
|
发表于 5-4-2008 07:06 PM
|
显示全部楼层
前面两个是Directory来的。你可以用is_dir()来坚定。
while ($file = readdir($dir))
{
$file = "D:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\wsd\\member_photo\\" . $file;
if (!is_dir($file)) {
$fs=filesize($file);
$moddate=date('F j, Y',filemtime($file));
echo ' <tr>
<td>'.$file.'</td>
<td>'.$fs. ' bytes</td>
<td>'.$moddate.'</td>';
}
}
不是Directory的,才show出来。这样就不会有那两个东西了。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 5-4-2008 11:14 PM
|
显示全部楼层
哦!原来如此~~那么$file具体的功用是什么呢?
再来再来,
如果我要search,display result的时候顺便display我save在directory的image, 应该怎样呢?
笨笨的试过echo可是好像乱echo一通....什么都没有 |
|
|
|
|
|
|
|
|
|
|
发表于 6-4-2008 12:25 AM
|
显示全部楼层
$file只是filename而已,没什么功能的。
你的file只存在folder,没存入database?如果是这样,那你必须compare filename跟user 输入的keyword咯。
大概是:
<?php
// something that the user key in
$keyword = $_POST['keyword'];
$current_dir = 'member_photo/';
$dir = opendir($current_dir);
while ($file = readdir($dir))
{
if (!is_dir($file)) {
$file = strtolower($file);
$keyword = strtolower($keyword);
if (strstr($file, $keyword)) {
// found. Display photo
$file = "D:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\wsd\\member_photo\\" . $file;
echo '<img src="' . $file . '">';
}
$file = "D:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\wsd\\member_photo\\" . $file;
}
}
closedir($dir);
?>
但这个方法不太好。如果file很多,会变慢。最好是upload file的同时,将filename存入database。这样searching比较快。
你研究一下,看看怎样。。。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 6-4-2008 01:00 AM
|
显示全部楼层
嗯,怎么说,我的result已经找到了,只是想要在result下面把相关image echo出来而已。
我的全部code是这样的, 就是那个红色部分failed掉
<?php
// Get the search variable from URL
$var = @$_GET['q'] ;
$trimmed = trim($var); //trim whitespace from the stored variable
// rows to return
$limit=10;
// check for an empty string and display a message.
if ($trimmed == ""
{
echo "<p> lease enter a search...</p>";
exit;
}
// check for a search parameter
if (!isset($var))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("localhost","root","root" ; //(host, username, password)
//specify database ** EDIT REQUIRED HERE **
mysql_select_db("peta" or die("Unable to select database" ; //select which database we're using
// Build SQL Query
$query = "select maplocation from mapinfo where maplocation like '%$trimmed%' or city like '%$trimmed%' or
poscode like '%$trimmed%' or
state like '%$trimmed%' or
areacovered like '%$trimmed%' ";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
// If we have no results, offer a google search as an alternative
if ($numrows == 0)
{
echo "<h4>Results</h4>";
echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>";
}
// next determine if s has been passed to script, if not use 0
if (empty($s)) {
$s=0;
}
// get results
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query" ;
// display what the person searched for
echo "<p>You searched for: "" . $var . ""</p>";
// begin to show results set
echo "Results<br>";
$count = 1 + $s ;
// now you can display the results returned
while ($row= mysql_fetch_array($result))
{
$title = $row["maplocation"];
$file = "C:\\xampp\\htdocs\\sc\\upload\\" . $file;
echo '<img src="' . $file . '">';
echo "$count.) $title" ;
$count++ ;
}
$currPage = (($s/$limit) + 1);
//break before paging
echo "<br />";
// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><<
Prev 10</a>  ";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$news=$s+$limit;
echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "<p>Showing results $b to $a of $numrows</p>";
?> |
|
|
|
|
|
|
|
|
|
|
发表于 6-4-2008 01:28 AM
|
显示全部楼层
试试将Path改成http的style,不要用C:\....。
Example:
$file = "http://localhost/sc/upload/" . $file;
echo '<img src="' . $file . '">';
就是将image的src写成 http://localhost/website/abc.jpg 的 format,试试。。。 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|