2013-04-08 49 views
0

我試圖上傳一個圖像,並與此圖像創建一個zip文件,我看了這裏的任何代碼,但我不太明白。請幫助。上傳一個圖像,並創建一個zip文件不工作

PHP

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<? 
require('conecta.php'); 
$uploaddir = '/var/www/subirImagenBD/'; 
$fechaFoto=date('YmdHis').'_'.basename($_FILES['Foto']['name']); 
    if (is_uploaded_file($_FILES['Foto']['tmp_name'])) { 
     $uploadfile = $uploaddir . $fecha . $fechaFoto; 
     move_uploaded_file($_FILES['Foto']['tmp_name'], $uploadfile); 
    $cFoto=basename($_FILES['Foto']['name']); 
    } 
    echo $cFoto." guardada en ".$uploaddir. $fechaFoto."<br>"; 
    $cSQL="INSERT INTO FOTOS (NOMBRE,PIC) VALUES (?,?)"; 
    $stmt=$oConni->prepare($cSQL); 
    $stmt->bind_param("ss", $fechaFoto, file_get_contents($uploaddir. $fechaFoto)); 
    $stmt->execute(); 
/* 
    $zipFile = $fechaFoto; 
$zipArchive = new ZipArchive(); 

if (!$zipArchive->open($zipFile, ZIPARCHIVE::OVERWRITE)) 
    die("Failed to create archive\n"); 

$zipArchive->addGlob($fechaFoto); 
if (!$zipArchive->status == ZIPARCHIVE::ER_OK) 
    echo "Failed to write local files to zip\n"; 

$zipArchive->close();*/ 


?> 
+0

$ fechaFoto純粹是文件名,也沒有任何目錄引用....除非您的腳本在文件所在的目錄中執行,否則addGlob()將不會找到該腳本...並且爲什麼在只添加單個文件時使用addGlob()方法,爲什麼不簡單地添加()? – 2013-04-08 15:55:26

+0

@Mark Ba​​ker我會試試看。 – jal 2013-04-08 16:04:36

+0

總是使用'<?php'作爲php的開始標記。你在這裏使用了<?? – 2013-04-08 16:09:24

回答