简体   繁体   English

PHP图像上传麻烦

[英]PHP Image Upload trouble

I am currently working on a Joomla! 我目前正在开发Joomla! website. 网站。 I am using the Jumi extension (which allows custom scripts to be made and executed within Joomla! itself) to create a simple file upload tool. 我正在使用Jumi扩展名(允许在Joomla!本身中创建和执行自定义脚本)来创建一个简单的文件上传工具。 The problem is that I get the following error: 问题是我得到以下错误:

Warning: copy(C:/xampp/htdocs/images/1253889508.jpg) [function.copy]: failed to open stream: No such file or directory in C:\\xampp\\htdocs\\Joomla\\components\\com_jumi\\jumi.php(25) : eval()'d code on line 61 警告:复制(C:/xampp/htdocs/images/1253889508.jpg)[function.copy]:无法打开流: C:\\ xampp \\ htdocs \\ Joomla \\ components \\ com_jumi \\ jumi.php中没有此类文件或目录(25) :第61行的eval()代码

The offending code is as follows: 令人讨厌的代码如下:

//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname='C:/xampp/htdocs/images/'.$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);

The full code is available here . 完整代码可在此处获得 Once I get this working, I will be modifying it to meet the needs of my website. 一旦开始运行,我将对其进行修改以满足我的网站的需求。

I'm not sure if the problem is a permissions issue with Jumi or if there is some other problem. 我不确定这是Jumi的权限问题还是其他问题。 The best I can tell is that for whatever reason, the temp file is not being created. 我能说的最好的是,无论出于何种原因,都不会创建临时文件。

Thanks for any tips you may have! 感谢您提供的任何提示!

Try this: 尝试这个:

if(move_uploaded_file($_FILES['image']['tmp_name'], $newname)){
    // move worked, carry on
}

And use relative paths instead of absolute ones. 并使用相对路径而不是绝对路径。

does your C:/xampp/htdocs/images directory actually exists? 您的C:/ xampp / htdocs / images目录实际存在吗?
if not create it manually or with mkdir() 如果不是手动创建或使用mkdir()创建

also try to use the constant DIRECTORY_SEPARATOR instead of hardcoding slashes 还尝试使用常量DIRECTORY_SEPARATOR而不是硬编码斜杠

Also you should use the move_uploaded_file() for this and not the copy() function. 另外,您应该为此使用move_uploaded_file()而不是copy()函数。

And never hardcode absolute paths into your scripts! 绝对不要将绝对路径硬编码到脚本中! instead get the root path and preferibly set it as a constant, this is mostly done with the dirname() function in the entry file, but joomla allready has a constant you can use for this. 取而代之的是获取根路径并将其设置为常量,这主要是通过条目文件中的dirname()函数完成的,但是joomla allready已经有一个常量可用于此目的。

$namename路径中的斜杠而不是反斜杠?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM