ringrazio tutti x la collaborazione
x andre3a - io sto provando in rete quindi ogni volta che faccio delle modifiche aggiorno l'ftp, perciò considerando quello che hai detto
invia.sendAndLoad("file.php",invia,"POST");
dovrebbe andare bene! giusto?
x and80- al momento sto solo facendo delle prove x risolvere lo scambio di variabili tra flash e php, ma il mio problema era quello di ripassare a flash il nome del file rinominato da php
Codice PHP:
<?php
$nuovo_nome = rand(0,1000)."_".$_FILES['Filedata']['name'] ;
//create the directory if doesn't exists (should have write permissons)
if(!is_dir("./public/3dgallery/high_res")) mkdir("./public/3dgallery/high_res", 0755);
//move the uploaded file
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./public/3dgallery/high_res/" .$nuovo_nome );
chmod("./public/3dgallery/high_res/".$nuovo_nome, 0777);
print "&ciccio=".$nuovo_nome."&";
?>
in pratica da flash tramite questo script
seleziono e mando in upload un file che php rinomina prima di caricare sul server, siccome mi serve recuperare il nuovo nome che php da al file, per mandarlo a flash che lo manderà al DB, ho bisogno di risolvere questo scambio di variabili.
al momento sto provando a far calcolare a flash una stringa random che saràinviata a php e che verrà aggiunta al nome del file, purtroppoperò non riconosce la variabile che mando a flash
cmq questi sono gli ultimi file su cui sto lavorando
as
Codice PHP:
//Allow this domain
//System.security.allowDomain("http://localhost/");
import flash.net.FileReference;
// The listener object listens for FileReference events.
var listener:Object = new Object();
prefixb = Math.round(1000*Math.random());
dati_send = new LoadVars()
dati_send.prefix = prefixb;
dati_send.sendAndLoad("upload.php",dati_send,"POST");
dati_send.onLoad = function(success) {
if (success) {
stato="ok";
}else{ stato="error";}
}
// When the user selects a file, the onSelect() method is called, and
// passed a reference to the FileReference object.
listener.onSelect = function(selectedFile:FileReference):Void {
//clean statusArea and details area
newname=prefixb+"_"+ selectedFile.name;
statusArea.text = ""
// Flash is attempting to upload the image.
statusArea.text += "File selected " +newname + "\n";
// Upload the file to the PHP script on the server.
selectedFile.upload("upload.php");
};
// the file is starting to upload.
listener.onOpen = function(selectedFile:FileReference):Void {
statusArea.text += "Uploading " + newname + ", wait!\n";
};
//Possible file upload errors
listener.onHTTPError = function(file:FileReference, httpError:Number):Void {
imagePane.contentPath = "error";
imagePane.content.errorMSG.text = "HTTPError number: "+httpError +"\nFile: "+ file.name;
}
listener.onIOError = function(file:FileReference):Void {
imagePane.contentPath = "error";
imagePane.content.errorMSG.text = "IOError: "+ file.name;
}
listener.onSecurityError = function(file:FileReference, errorString:String):Void {
imagePane.contentPath = "error";
imagePane.content.errorMSG.text = "SecurityError: "+SecurityError+"\nFile: "+ file.name;
}
// the file has uploaded
listener.onComplete = function(selectedFile:FileReference):Void {
// Notify the user that Flash is starting to download the image.
statusArea.text += "Upload of " + newname + " finished\n";
//Show file details
filenewname.text=newname;
filename.text=selectedFile.name;
filesize.text=selectedFile.size+" byte";
//details.text = ""
// for(i in selectedFile) details.text +="[b]"+i+":[/b] "+selectedFile[i]+"\n"
// Call the custom downloadImage() function.
downloadImage(selectedFile.name);
};
var imageFile:FileReference = new FileReference();
imageFile.addListener(listener);
uploadBtn.onPress = uploadImage;
imagePane.addEventListener("complete", imageDownloaded);
// Call the uploadImage() function, opens a file browser dialog.
function uploadImage(event:Object):Void {
imageFile.browse([{description: "Image Files", extension: "*.jpg;*.gif;*.png;"}]);
}
// If the image does not download, the event object's total property
// will equal -1. In that case, display am error message
function imageDownloaded(event:Object):Void {
if(event.total == -1) {
imagePane.contentPath = "error";
}
}
// show uploaded image in scrollPane
function downloadImage(file:Object):Void {
imagePane.contentPath = "./public/3dgallery/high_res/" + file;
}
stop()
php
Codice PHP:
<?php
$nome=$_POST['prefix'];
$nuovo_nome = $nome;
if(!is_dir("./public/3dgallery/high_res")) mkdir("./public/3dgallery/high_res", 0755);
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./public/3dgallery/high_res/" .$nuovo_nome."_".$_FILES['Filedata']['name'] );
chmod("./public/3dgallery/high_res/".$nuovo_nome."_".$_FILES['Filedata']['name'], 0777);
?>
spero di non aver scritto troppo (anche se è così
)