接收和上传文件而不保存PHP

时间:2011-07-28 22:49:41

标签: php facebook

我正在使用flash将图像上传到php脚本,该文件将文件保存在同一目录中,然后将其上传到Facebook相册。这样我就会得到一堆磁盘空间。 有没有办法绕过保存并直接上传?

下面的脚本:

$upload_dir = $_SERVER['DOCUMENT_ROOT'] .  dirname($_SERVER['PHP_SELF']) . '/';
$upload_url = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']) . '/';
$message ="";

$temp_name = $_FILES['Filedata']['tmp_name'];
$file_name = $_FILES['Filedata']['name']; 
$file_name = str_replace("","",$file_name);
$file_name = str_replace("'","",$file_name);
$file_path = $upload_dir.$file_name;

move_uploaded_file($temp_name, $file_path);

然后上传我正在使用:

 $attachment =  array (
    'access_token' => $appAccessToken,
    'message'=>  "NAME: ".$name.");
$attachment['image'] = '@' . realpath($file_path);

提前致谢!

2 个答案:

答案 0 :(得分:3)

//get it
$upload_dir = $_SERVER['DOCUMENT_ROOT'] .  dirname($_SERVER['PHP_SELF']) . '/';
$upload_url = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']) . '/';
$message = "";

$temp_name = $_FILES['Filedata']['tmp_name'];
$file_name = $_FILES['Filedata']['name']; 
$file_name = str_replace("","",$file_name);
$file_name = str_replace("'","",$file_name);
$file_path = $upload_dir.$file_name;

//save it
move_uploaded_file($temp_name, $file_path); 


//upload it to FB
$attachment =  array (
    'access_token' => $appAccessToken,
    'message'=>  "NAME: ".$name);
$attachment['image'] = '@' . realpath($file_path);
//more code to upload it....

//delete it
unlink($file_path);
  • 搞定
  • 保存
  • 将其上传至Fb
  • 将其删除(使用unlink()功能)

答案 1 :(得分:1)

我想,我不确定,您可以从客户端计算机发送附件(如C:\ Folder1 \ Folder2 \ Image1.jpg),而不必将其上传到服务器中将其作为附件发送。 试一试。