在PHP中移动上传的文件

时间:2021-08-02 16:05:25

I need to resize an uploaded image. The class that resizes needs to get the location of the image to be worked with. It returns the image in a variable.

我需要调整上传图片的大小。调整大小的类需要获取要处理的图像的位置。它返回变量中的图像。

However, when I try to get the path to the image, I get from $_FILES['profile_upload']['tmp_name'] the following: C:\xampp\tmp\php1C5.tmp I don't get the actual file, even though the tmp folder contains it!

但是,当我尝试获取图像的路径时,我从$ _FILES ['profile_upload'] ['tmp_name']得到以下内容:C:\ xampp \ tmp \ php1C5.tmp我没有得到实际的文件,即使tmp文件夹包含它!

How can I get the actual filename? Another question - for how long are the files stored in tmp, and when do they get deleted?

我怎样才能得到实际的文件名?另一个问题 - 文件存储在tmp中有多长时间,什么时候被删除?

By the way, does the Zend Framework have a good image manipulation interface?

那么,Zend Framework是否有一个良好的图像处理界面?

2 个解决方案

#1


You should complete the whole file upload setup with something similar and then the variable $_FILES['uploadedfile']['name'] will also contain the original file name:

您应该使用类似的东西完成整个文件上传设置,然后变量$ _FILES ['uploadedfile'] ['name']也将包含原始文件名:

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

#2


To address your second point: Files are stored until the script they were uploaded to finishes.

解决第二点:文件存储直到它们上传的脚本完成。

#1


You should complete the whole file upload setup with something similar and then the variable $_FILES['uploadedfile']['name'] will also contain the original file name:

您应该使用类似的东西完成整个文件上传设置,然后变量$ _FILES ['uploadedfile'] ['name']也将包含原始文件名:

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

#2


To address your second point: Files are stored until the script they were uploaded to finishes.

解决第二点:文件存储直到它们上传的脚本完成。