jQuery로 "향신료"를주고 싶지만 실제로 작동하도록 만드는 방법을 생각할 수없는 코드 조각을 만들고 있습니다. 나는 그것의 단순함을 확신하고, 나는 단지 나를 얻기 위해 약간의 충고가 필요하다.PHP Foreach and jQuery
파일을 다운로드 한 다음 S3 버킷에 업로드하는 큰 루프를 시작하기 위해 Ajax 요청을 내보내는 코드를 만들고 싶습니다. 내가 갇혀있는 곳은 파일이 업로드 될 때마다 브라우저에 다시 요청을 보내고 완료시 화면에 일련의 텍스트를 출력하려고합니다.
나는 프론트 엔드 코드가 전혀 작동하지 않는다. 단지 내 머리를 논리로 둘러싼 다. 어떤 아이디어라도?
PHP 백엔드 코드 :
<?php
public function photos($city) {
if(isset($city))
$this->city_name = "{$city}";
// grab data array from Dropbox folder
$postcard_assets = $this->conn->getPostcardDirContent("{$this->city_name}", "Photos", TRUE);
$data = array();
foreach($postcard_assets['contents'] as $asset) {
//only grab contents in root folder... do not traverse into sub folders && make sure the folder is not empty
if(!$asset['is_dir'] && $asset['bytes'] > 0) {
// get information on file
$file = pathinfo($asset['path']);
// download file from Dropbox
$original_file = $this->conn->downloadFile(str_replace(" ", "%20", $asset['path']));
// create file name
$file_name = $this->cleanFileName($file['basename']);
// write photo to TMP_DIR ("/tmp/photos/") for manipulation
$fh = fopen(self::TMP_DIR . $file_name, 'w');
fwrite($fh, $original_file);
fclose($fh);
// Resize photo
$this->resize_photo($file_name);
// hash file name
$raw_file = sha1($file_name);
// create S3 hashed name
$s3_file_name = "1_{$raw_file}.{$file['extension']}";
// Upload manipulated file to S3
$this->s3->putObject($s3_file_name, file_get_contents(self::TMP_DIR . $file_name), $this->photo_s3_bucket, 'public-read');
// check to see if file exists in S3 bucket
$s3_check = $this->s3->getObjectInfo($s3_file_name, $this->photo_s3_bucket);
// if the file uploaded successully to S3, load into DB
if($s3_check['content-length'] > 0) {
$data['src'] = $s3_file_name;
$data['width'] = $this->width;
$data['height'] = $this->height;
Photo::create_postcard_photo($data, "{$this->city_name}");
// Now that the photo has been uploaded to S3 and saved in the DB, remove local file for cleanup
unlink(self::TMP_DIR . $file_name);
echo "{$file_name} uploaded to S3 and resized!<br />";
}
}
}
// after loop is complete, kill script or nasty PHP header warnings will appear
exit();
}
?>
지금까지 무엇이 있습니까? – Neal
백엔드 PHP 코드를 포함하도록 게시물이 업데이트되었습니다. 루프 foreach 파일을 완성 할 때마다 jQuery를 출력하는 방법을 모르겠습니다. 감사합니다! – dennismonsewicz