wordpress 上传文件路径(wordpress文件上传插件)

WordPress作为全球最受欢迎的博客平台和内容管理系统,拥有着强大的功能和灵活的扩展性。而在WordPress中,上传文件是日常操作中非常常见的任务。今天,我们就来聊聊WordPress上传文件路径的那些事儿,帮助你轻松掌握文件管理技巧。

一、WordPress上传文件路径概述

在WordPress中,上传的文件会存储在服务器上的特定路径。这个路径通常位于网站的根目录下,具体位置取决于你的服务器配置和网站结构。以下是一个常见的WordPress上传文件路径:

“`

/wp-content/uploads/年/月/

“`

其中,`/wp-content/`是WordPress默认的主题和插件文件存储路径,`/uploads/`则是上传文件的存放路径。年、月则是上传文件的时间戳,方便管理和查找。

二、WordPress上传文件路径的设置与修改

1. 默认上传文件路径

一般情况下,WordPress默认的上传文件路径是上述所提到的。如果你没有修改过这个路径,那么默认的设置就足够满足日常需求。

2. 修改上传文件路径

如果你想要修改WordPress上传文件路径,可以通过以下几种方法实现:

(1)直接修改WordPress配置文件

打开WordPress根目录下的`wp-config.php`文件,找到以下代码:

“`php

define(‘UPLOADS’, ‘/wp-content/uploads/’);

“`

将`/wp-content/uploads/`替换为你想要的新路径,例如:

“`php

define(‘UPLOADS’, ‘/custom/uploads/’);

“`

保存并关闭文件。注意:在修改路径时,确保新路径已经存在于服务器上。

(2)通过插件修改上传文件路径

市面上有许多插件可以帮助你轻松修改WordPress上传文件路径,例如`Upload Path Editor`、`Directory Protection`等。通过这些插件,你可以方便地设置新的上传文件路径,并添加安全措施。

三、WordPress上传文件路径管理技巧

1. 合理规划上传文件路径

在管理上传文件时,合理规划路径至关重要。以下是一些规划路径的建议:

  • 按年月分类:将上传的文件按照年月进行分类,便于查找和管理。
  • 按分类或标签分类:如果你的网站内容丰富,可以将文件按照文章分类或标签进行分类。
  • 自定义命名规则:为上传的文件设置自定义命名规则,便于识别和搜索。

2. 定期清理上传文件

随着时间的推移,上传文件夹中可能会积累大量的无用文件。为了保持网站性能和安全性,建议定期清理上传文件夹,删除过期或无用的文件。

3. 备份上传文件

在修改上传文件路径或清理文件之前,务必先备份上传文件夹,以免丢失重要文件。

掌握WordPress上传文件路径的管理技巧,可以帮助你更好地组织和管理网站内容。通过合理规划路径、定期清理文件和备份重要数据,让你的WordPress网站更加高效、安全。希望本文能对你有所帮助,如有疑问,欢迎在评论区留言交流。

WordPress 3.5版本怎么修改上传图片路径

Wordpress 3.5版本修改上传图片路径的方法如下:

打开wpconfig.php文件:

在Wordpress根目录中,找到并打开wpconfig.php文件。添加定义:

在wpconfig.php文件的任意位置,添加以下一行代码:phpdefine;这行代码的作用是定义一个新的上传目录路径。例如,如果你的域名是xxx.com,那么图片上传路径将被设置为xxx.com/uploads/。3.保存文件:确保添加完定义后,保存wpconfig.php文件。4.测试上传:登录Wordpress后台,尝试上传一张图片以测试设置是否成功。注意事项:在添加定义时,确保分号是存在的,这是PHP语法的要求。修改上传路径后,之前上传的图片不会自动移动到新路径,需要手动迁移或设置重定向。确保新的上传目录具有正确的写权限,以便Wordpress能够正常上传文件。

如何修改WordPress安装路径

虽然很多人建议不要随意修改

WordPress

的安装路径,但是,有的时候也有不得不改的理由(比如本站曾经修改

WordPress

安装路径),也有人看到自己网站根目录下面那么夺得文件,显得不整洁,于是想改变

WordPress

安装路径。当然,WordPress

安装路径也不是改不得,但是,改变以后要保证原来的网页链接不发生改变。

首先,请删除网站根目录和

WordPress

安装路径下面的

htaccess

文件;之后,登陆后台

>>

设置

>>

常规,按照下面的方式设置

WordPress

地址(URL)和

站点地址(URL),并保存更改。

更改之后,会出现网页打不开的情况,这是很正常的,不用担心。接下来请登陆

FTP

,将

WordPress

的程序文件放入网站根目录的

admin

文件夹中(和修改的

WordPress

地址保持一致),并下载

index.php

文件,用专用编辑器(推荐

UlraEdit

)打开

index.php

文件,查找

require(‘./wp-blog-header.php’);

修改为

require(‘./admin/wp-blog-header.php’);

保存后,将修改后的

index.php

文件上传至网站根目录。

这样,WordPress

的安装路径已经修改好了。这时候,打开你的网站,查看一下,你的网站网址有没有发生改动?

如果你是从头开始安装

WordPress

,不妨参考这样的安装方式:推荐

WordPress

安装方式。

注:每次修改

WordPress

安装地址和站点地址,WordPress会生成新的

htaccess

文件。

求ASP.NET WEB项目文件夹上传下载解决方案

ASP.NET上传文件用FileUpLoad就可以,但是对文件夹的操作却不能用FileUpLoad来实现。

下面这个示例便是使用ASP.NET来实现上传文件夹并对文件夹进行压缩以及解压。

ASP.NET页面设计:TextBox和Button按钮。

TextBox中需要自己受到输入文件夹的路径(包含文件夹),通过Button实现选择文件夹的问题还没有解决,暂时只能手动输入。

两种方法:生成rar和zip。

1.生成rar

using Microsoft.Win32;

using System.Diagnostics;

protected void Button1Click(object sender, EventArgs e)

{

RAR(@”E:\95413594531\GIS”,”tmptest”,@”E:\95413594531\”);

}

///

///压缩文件

///

///需要压缩的文件夹或者单个文件

///生成压缩文件的文件名

///生成压缩文件保存路径

///

protected bool RAR(string DFilePath, string DRARName,string DRARPath)

{

String therar;

RegistryKey theReg;

Object theObj;

String theInfo;

ProcessStartInfo theStartInfo;

Process theProcess;

try

{

theReg= Registry.ClassesRoot.OpenSubKey(@”Applications\WinRAR.exe\Shell\Open\Command”);//注:未在注册表的根路径找到此路径

theObj= theReg.GetValue(“”);

therar= theObj.ToString();

theReg.Close();

therar= therar.Substring(1, therar.Length- 7);

theInfo=” a”+””+ DRARName+””+ DFilePath+”-ep1″;//命令+压缩后文件名+被压缩的文件或者路径

theStartInfo= new ProcessStartInfo();

theStartInfo.FileName= therar;

theStartInfo.Arguments= theInfo;

theStartInfo.WindowStyle= ProcessWindowStyle.Hidden;

theStartInfo.WorkingDirectory= DRARPath;//RaR文件的存放目录。

theProcess= new Process();

theProcess.StartInfo= theStartInfo;

theProcess.Start();

theProcess.WaitForExit();

theProcess.Close();

return true;

}

catch(Exception ex)

{

return false;

}

}

///

///解压缩到指定文件夹

///

///压缩文件存在的目录

///压缩文件名称

///解压到文件夹

///

protected bool UnRAR(string RARFilePath,string RARFileName,string UnRARFilePath)

{

//解压缩

String therar;

RegistryKey theReg;

Object theObj;

String theInfo;

ProcessStartInfo theStartInfo;

Process theProcess;

try

{

theReg= Registry.ClassesRoot.OpenSubKey(@”Applications\WinRar.exe\Shell\Open\Command”);

theObj= theReg.GetValue(“”);

therar= theObj.ToString();

theReg.Close();

therar= therar.Substring(1, therar.Length- 7);

theInfo=@” X”+””+ RARFilePath+ RARFileName+””+ UnRARFilePath;

theStartInfo= new ProcessStartInfo();

theStartInfo.FileName= therar;

theStartInfo.Arguments= theInfo;

theStartInfo.WindowStyle= ProcessWindowStyle.Hidden;

theProcess= new Process();

theProcess.StartInfo= theStartInfo;

theProcess.Start();

return true;

}

catch(Exception ex)

{

return false;

}

}

注:这种方法在在电脑注册表中未找到应有的路径,未实现,仅供参考。

2.生成zip

通过调用类库ICSharpCode.SharpZipLib.dll

该类库可以从网上下载。也可以从本链接下载:SharpZipLib_0860_Bin.zip

增加两个类:Zip.cs和UnZip.cs

(1)Zip.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.IO;

using System.Collections;

using ICSharpCode.SharpZipLib.Checksums;

using ICSharpCode.SharpZipLib.Zip;

namespace UpLoad

{

///<summary>

///功能:压缩文件

/// creator chaodongwang 2009-11-11

///</summary>

public class Zip

{

///<summary>

///压缩单个文件

///</summary>

///<param name=”FileToZip”>被压缩的文件名称(包含文件路径)</param>

///<param name=”ZipedFile”>压缩后的文件名称(包含文件路径)</param>

///<param name=”CompressionLevel”>压缩率0(无压缩)-9(压缩率最高)</param>

///<param name=”BlockSize”>缓存大小</param>

public void ZipFile(string FileToZip, string ZipedFile, int CompressionLevel)

{

//如果文件没有找到,则报错

if(!System.IO.File.Exists(FileToZip))

{

throw new System.IO.FileNotFoundException(“文件:”+ FileToZip+”没有找到!”);

}

if(ZipedFile== string.Empty)

{

ZipedFile= Path.GetFileNameWithoutExtension(FileToZip)+”.zip”;

}

if(Path.GetExtension(ZipedFile)!=”.zip”)

{

ZipedFile= ZipedFile+”.zip”;

}

////如果指定位置目录不存在,创建该目录

//string zipedDir= ZipedFile.Substring(0,ZipedFile.LastIndexOf(“\\”));

//if(!Directory.Exists(zipedDir))

//Directory.CreateDirectory(zipedDir);

//被压缩文件名称

string filename= FileToZip.Substring(FileToZip.LastIndexOf('\\')+ 1);

System.IO.FileStream StreamToZip= new System.IO.FileStream(FileToZip, System.IO.FileMode.Open, System.IO.FileAccess.Read);

System.IO.FileStream ZipFile= System.IO.File.Create(ZipedFile);

ZipOutputStream ZipStream= new ZipOutputStream(ZipFile);

ZipEntry ZipEntry= new ZipEntry(filename);

ZipStream.PutNextEntry(ZipEntry);

ZipStream.SetLevel(CompressionLevel);

byte[] buffer= new byte[2048];

System.Int32 size= StreamToZip.Read(buffer, 0, buffer.Length);

ZipStream.Write(buffer, 0, size);

try

{

while(size< StreamToZip.Length)

{

int sizeRead= StreamToZip.Read(buffer, 0, buffer.Length);

ZipStream.Write(buffer, 0, sizeRead);

size+= sizeRead;

}

}

catch(System.Exception ex)

{

throw ex;

}

finally

{

ZipStream.Finish();

ZipStream.Close();

StreamToZip.Close();

}

}

///<summary>

///压缩文件夹的方法

///</summary>

public void ZipDir(string DirToZip, string ZipedFile, int CompressionLevel)

{

//压缩文件为空时默认与压缩文件夹同一级目录

if(ZipedFile== string.Empty)

{

ZipedFile= DirToZip.Substring(DirToZip.LastIndexOf(“\\”)+ 1);

ZipedFile= DirToZip.Substring(0, DirToZip.LastIndexOf(“\\”))+”\\”+ ZipedFile+”.zip”;

}

if(Path.GetExtension(ZipedFile)!=”.zip”)

{

ZipedFile= ZipedFile+”.zip”;

}

using(ZipOutputStream zipoutputstream= new ZipOutputStream(File.Create(ZipedFile)))

{

zipoutputstream.SetLevel(CompressionLevel);

Crc32 crc= new Crc32();

Hashtable fileList= getAllFies(DirToZip);

foreach(DictionaryEntry item in fileList)

{

FileStream fs= File.OpenRead(item.Key.ToString());

byte[] buffer= new byte[fs.Length];

fs.Read(buffer, 0, buffer.Length);

ZipEntry entry= new ZipEntry(item.Key.ToString().Substring(DirToZip.Length+ 1));

entry.DateTime=(DateTime)item.Value;

entry.Size= fs.Length;

fs.Close();

crc.Reset();

crc.Update(buffer);

entry.Crc= crc.Value;

zipoutputstream.PutNextEntry(entry);

zipoutputstream.Write(buffer, 0, buffer.Length);

}

}

}

///<summary>

///获取所有文件

///</summary>

///<returns></returns>

private Hashtable getAllFies(string dir)

{

Hashtable FilesList= new Hashtable();

DirectoryInfo fileDire= new DirectoryInfo(dir);

if(!fileDire.Exists)

{

throw new System.IO.FileNotFoundException(“目录:”+ fileDire.FullName+”没有找到!”);

}

this.getAllDirFiles(fileDire, FilesList);

this.getAllDirsFiles(fileDire.GetDirectories(), FilesList);

return FilesList;

}

///<summary>

///获取一个文件夹下的所有文件夹里的文件

///</summary>

///<param name=”dirs”></param>

///<param name=”filesList”></param>

private void getAllDirsFiles(DirectoryInfo[] dirs, Hashtable filesList)

{

foreach(DirectoryInfo dir in dirs)

{

foreach(FileInfo file in dir.GetFiles(“*.*”))

{

filesList.Add(file.FullName, file.LastWriteTime);

}

this.getAllDirsFiles(dir.GetDirectories(), filesList);

}

}

///<summary>

///获取一个文件夹下的文件

///</summary>

///<param name=”strDirName”>目录名称</param>

///<param name=”filesList”>文件列表HastTable</param>

private void getAllDirFiles(DirectoryInfo dir, Hashtable filesList)

{

foreach(FileInfo file in dir.GetFiles(“*.*”))

{

filesList.Add(file.FullName, file.LastWriteTime);

}

}

}

}

(2)UnZip.cs

using System.Collections.Generic;

using System.Linq;

using System.Web;

///<summary>

///解压文件

///</summary>

using System;

using System.Text;

using System.Collections;

using System.IO;

using System.Diagnostics;

using System.Runtime.Serialization.Formatters.Binary;

using System.Data;

using ICSharpCode.SharpZipLib.Zip;

using ICSharpCode.SharpZipLib.Zip.Compression;

using ICSharpCode.SharpZipLib.Zip.Compression.Streams;

namespace UpLoad

{

///<summary>

///功能:解压文件

/// creator chaodongwang 2009-11-11

///</summary>

public class UnZipClass

{

///<summary>

///功能:解压zip格式的文件。

///</summary>

///<param name=”zipFilePath”>压缩文件路径</param>

///<param name=”unZipDir”>解压文件存放路径,为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹</param>

///<param name=”err”>出错信息</param>

///<returns>解压是否成功</returns>

public void UnZip(string zipFilePath, string unZipDir)

{

if(zipFilePath== string.Empty)

{

throw new Exception(“压缩文件不能为空!”);

}

if(!File.Exists(zipFilePath))

{

throw new System.IO.FileNotFoundException(“压缩文件不存在!”);

}

//解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹

if(unZipDir== string.Empty)

unZipDir= zipFilePath.Replace(Path.GetFileName(zipFilePath), Path.GetFileNameWithoutExtension(zipFilePath));

if(!unZipDir.EndsWith(“\\”))

unZipDir+=”\\”;

if(!Directory.Exists(unZipDir))

Directory.CreateDirectory(unZipDir);

using(ZipInputStream s= new ZipInputStream(File.OpenRead(zipFilePath)))

{

ZipEntry theEntry;

while((theEntry= s.GetNextEntry())!= null)

{

string directoryName= Path.GetDirectoryName(theEntry.Name);

string fileName= Path.GetFileName(theEntry.Name);

if(directoryName.Length> 0)

{

Directory.CreateDirectory(unZipDir+ directoryName);

}

if(!directoryName.EndsWith(“\\”))

directoryName+=”\\”;

if(fileName!= String.Empty)

{

using(FileStream streamWriter= File.Create(unZipDir+ theEntry.Name))

{

int size= 2048;

byte[] data= new byte[2048];

while(true)

{

size= s.Read(data, 0, data.Length);

if(size> 0)

{

streamWriter.Write(data, 0, size);

}

else

{

break;

}

}

}

}

}

}

}

}

}

以上这两个类库可以直接在程序里新建类库,然后复制粘贴,直接调用即可。

主程序代码如下所示:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Drawing;

using Microsoft.Win32;

using System.Diagnostics;

namespace UpLoad

{

public partial class UpLoadForm: System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void Button1_Click(object sender, EventArgs e)

{

if(TextBox1.Text==””)//如果输入为空,则弹出提示

{

this.Response.Write(“<script>alert('输入为空,请重新输入!');window.opener.location.href=window.opener.location.href;</script>”);

}

else

{

//压缩文件夹

string zipPath= TextBox1.Text.Trim();//获取将要压缩的路径(包括文件夹)

string zipedPath=@”c:\temp”;//压缩文件夹的路径(包括文件夹)

Zip Zc= new Zip();

Zc.ZipDir(zipPath, zipedPath, 6);

this.Response.Write(“<script>alert('压缩成功!');window.opener.location.href=window.opener.location.href;</script>”);

//解压文件夹

UnZipClass unZip= new UnZipClass();

unZip.UnZip(zipedPath+”.zip”,@”c:\temp”);//要解压文件夹的路径(包括文件名)和解压路径(temp文件夹下的文件就是输入路径文件夹下的文件)

this.Response.Write(“<script>alert('解压成功!');window.opener.location.href=window.opener.location.href;</script>”);

}

}

}

}

本方法经过测试,均已实现。

另外,附上另外一种上传文件方法,经测试已实现,参考链接:

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享