照片上传 - 不适用于Linux服务器
我有这个代码,在Windows服务器上完美运行,但现在我正在尝试在Linux服务器上运行它,表单提交,我没有错误,但是
照片没有上传,标题文件没有写....任何想法为什么?
<?php
包括''gall_settings.inc'';
//检查目录是否存在。
if(!is_dir(" $) upload_dir"))
{
die("目录< b>($ upload_dir)< / b>不存在");
}
//检查目录是否可写。
if(!is_writeable(" $ upload_dir")){\\ n br />
die("目录< b>($ upload_dir)< / b>是不可写的,
请Chmod(777)");
}
//首先检查文件是否被选中
// is_filetoupload_file(''filename'')如果
//文件是通过HTTP POST的filetoupload。否则返回false。
if(is_uploaded_file($ _ FILES [''filetoupload''] [''tmp_name'']))
{
//获取文件大小
$ size = $ _FILES [''filetoupload''] [''size''];
//确保$ size小于1MB(1000000字节)
if($ size> $ size_bytes)
{
echo"< b> ;错误!< / b>< br>" ;;
echo"文件太大。请再试一次。;
include(''gall_footer.php'');
exit();
}
$ gallery = $ _POST [gallery];
//检查用户是否选择了要上传的照片库。
if($ gallery!=="")
{
开关($ gallery)
{
case" 01":
echo" Gallery:01< br>" ;;
break;
case" 02":
echo" Gallery:02< br>" ;;
break;
case" 03":
echo" Gallery:03< br>" ;;
break;
case" 04":
echo Gallery:04< br>" ;;
break;
case" 05":
echo" Gallery:05< br>" ;;
休息;
默认:
$ gallery =''01'';
echo错误:未选择有效图库。< br>" ;;
echo" File has已保存到默认图库:图库01< br>< br>" ;;
}
}
其他
{
echo"< b>错误!< / b>< br>" ;;
echo"请选择有效的图库: < br>" ;;
include(''gall_footer.php'');
exit();
}
// $ filename将保存从表单提交的文件名的值。
// $ caption保存用户照片的标题值
写在表格上。
$ filename = $ _FILES [''filetoupload''] [''name''];
$ caption = $ _POST [''caption''];
//从文件名和标题中删除非法字符
$ strippedNam = preg_replace(''/ [^ a-z0-9 _。,] / i'','''',$ filename);
$ strippedCap = preg_replace(''/ [^ a-z0-9_。,] / i'','''',$ caption);
//检查文件是否已经是EXISTS。
if(file_exists($ upload_dir。$ strippedNam)){
echo"< b>错误!< / b>< br>";
echo"文件< b> $ strippedNam< / b>已经存在" ;;
include(''gall_footer.php'');
退出( );
}
//将文件移动到您选择的目录
// move_filetoupload_file(''filename' ',''destination'')将filetoupload
文件移动到新位置。
如果
(move_uploaded_file($ _ FILES ['' filetoupload''] [''tmp_name''],$ upload_dir。$ strippedNam))
{
//告诉用户该文件已被已上传
echo"< b>上传完成!< / b>< br>" ;;
echo"文件名:< a href =' '$ upload_dir $ strippedNam''> $ strippedNam< / a>< br>" ;;
echo" Caption:$ strippedCap< br>< br>";
echo"< a href = / page.php?t itle = gallery>转到公开照片
图库< / a>< br>< br>" ;;
include(''gall_footer.php'') ;
//在追加模式下打开字幕文件
$ imageFile = $ strippedNam;
$ captionText = $ strippedCap;
//设置要写入文件的字符串
$ values =" $ gallery | $ imageFile | $ captionText \\\\ n" ;
//打开文件进行截断写作
$ fp = fopen(" $ captionFile"," a")或die(")无法打开
写入的数据文件!");
$ numBytes = fwrite($ fp,$ values)或死(不能将值写入文件!");
fclose($ fp);
// echo"成功写入$ numBytes字节到数据文件! ;;
退出();
}
其他
{
//打印错误
echo"< b>错误!< / b>< br>" ;;
echo& ;上传文件时出现问题< br>" ;;
echo"请检查文件名,然后重试。< br>";
include (''gall_footer.php'');
退出();
}
}
?>
I have this code, works perfectly on Windows server, but now i''m trying
to run it on a Linux server, the form submits, i get no errors, but the
photo doesnt upload, and the caption file doesnt write.... any ideas why??
<?php
include ''gall_settings.inc'';
//check if the directory exist or not.
if (!is_dir("$upload_dir"))
{
die ("The directory <b>($upload_dir)</b> doesn''t exist");
}
//check if the directory is writable.
if (!is_writeable("$upload_dir")){
die ("The directory <b>($upload_dir)</b> is NOT writable,
Please Chmod (777)");
}
//Check first if a file has been selected
//is_filetoupload_file(''filename'') returns true if
//a file was filetoupload via HTTP POST. Returns false otherwise.
if (is_uploaded_file($_FILES[''filetoupload''][''tmp_name'']))
{
//Get the Size of the File
$size = $_FILES[''filetoupload''][''size''];
//Make sure that $size is less than 1MB (1000000 bytes)
if ($size > $size_bytes)
{
echo "<b>Error!</b><br>";
echo "File Too Large. Please try again.";
include (''gall_footer.php'');
exit();
}
$gallery = $_POST[gallery];
//check if the user has selected photo gallery to upload to.
if ($gallery !== "")
{
switch($gallery)
{
case "01":
echo "Gallery: 01<br>";
break;
case "02":
echo "Gallery: 02<br>";
break;
case "03":
echo "Gallery: 03<br>";
break;
case "04":
echo "Gallery: 04<br>";
break;
case "05":
echo "Gallery: 05<br>";
break;
default:
$gallery = ''01'';
echo "ERROR: Valid Gallery was not selected.<br>";
echo "File has been saved into Default Gallery: Gallery 01<br><br>";
}
}
else
{
echo "<b>Error!</b><br>";
echo "Please select a valid Gallery:<br>";
include (''gall_footer.php'');
exit();
}
// $filename will hold the value of the file name submitted from the form.
// $caption holds the value of the caption for the photo that the user
has written on the form.
$filename = $_FILES[''filetoupload''][''name''];
$caption = $_POST[''caption''];
// strip illegal characters from Filename and Caption
$strippedNam = preg_replace(''/[^a-z0-9_., ]/i'','''',$filename);
$strippedCap = preg_replace(''/[^a-z0-9_., ]/i'','''',$caption);
// Check if file is Already EXISTS.
if(file_exists($upload_dir.$strippedNam)){
echo "<b>Error!</b><br>";
echo "File <b>$strippedNam </b>already exists";
include (''gall_footer.php'');
exit();
}
//Move the File to the Directory of your choice
//move_filetoupload_file(''filename'',''destination'') Moves an filetoupload
file to a new location.
if
(move_uploaded_file($_FILES[''filetoupload''][''tmp_name''],$upload_dir.$strippedNam))
{
//tell the user that the file has been uploaded
echo "<b>Upload Complete!</b><br>";
echo "Filename: <a href=''$upload_dir$strippedNam''>$strippedNam</a><br>";
echo "Caption: $strippedCap <br><br>";
echo "<a href=/page.php?title=gallery>Go to Public Photo
Gallery</a><br><br>";
include (''gall_footer.php'');
// Open captions file in Append mode
$imageFile = $strippedNam;
$captionText = $strippedCap;
// Set the string to be written to the file
$values = "$gallery|$imageFile|$captionText\r\n";
// Open the file for truncated writing
$fp = fopen("$captionFile", "a") or die("Couldn''t open data file for
writing!");
$numBytes = fwrite($fp, $values) or die("Couldn''t write values to file!");
fclose($fp);
// echo "Wrote $numBytes bytes to data file successfully!";
exit();
}
else
{
//Print error
echo "<b>Error!</b><br>";
echo "There was a problem uploading your file<br>";
echo "Please check the filename and try again.<br>";
include (''gall_footer.php'');
exit();
}
}
?>
upload_dir"))
{
die("目录< b>(
upload_dir"))
{
die ("The directory <b>(
upload_dir)< / b>不存在");
}
//检查目录是否可写。
if(!is_writeable ("
upload_dir)</b> doesn''t exist");
}
//check if the directory is writable.
if (!is_writeable("
upload_dir")){
die("目录< b>(
upload_dir")){
die ("The directory <b>(