PHP图片上传麻烦

时间:2009-09-25 14:43:26

标签: php joomla image-uploading

我目前正在为Joomla工作!网站。我正在使用Jumi扩展(允许在Joomla!本身内制作和执行自定义脚本)来创建一个简单的文件上传工具。问题是我收到以下错误:

警告:复制(C:/xampp/htdocs/images/1253889508.jpg)[function.copy]:无法打开流: C:\中没有此类文件或目录xampp \ htdocs \ Joomla \ components \ com_jumi \ jumi.php(25):eval()代码在线 61

违规代码如下:

//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);

完整代码可用here。一旦我开始工作,我将修改它以满足我的网站的需求。

我不确定问题是否是Jumi的权限问题,或者是否存在其他问题。我能说的最好的是,无论出于何种原因,都没有创建临时文件。

感谢您提供的任何提示!

3 个答案:

答案 0 :(得分:6)

试试这个:

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

使用相对路径而不是绝对路径。

答案 1 :(得分:3)

您的C:/ xampp / htdocs / images目录是否确实存在? 如果不是手动创建或使用mkdir()

也尝试使用常量DIRECTORY_SEPARATOR而不是硬编码斜杠

此外,您应该使用move_uploaded_file()而不是copy()函数。

永远不会硬编码绝对路径进入您的脚本!相反,获取根路径并优先将其设置为常量,这主要通过条目文件中的dirname()函数完成,但是joomla allready有一个常量,您可以使用它。

答案 2 :(得分:0)

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

相关问题