Jump to content

Recommended Posts

i use flash for making games in web.

i have the following scripy which enable upload and download images.

<?php

 

if (is_uploaded_file($_FILES['Filedata']['tmp_name'])) {

$uploadDirectory = "uploads/";

$uploadFile = $uploadDirectory . basename($_FILES['Filedata']['name']);

copy($_FILES['Filedata']['tmp_name'], $uploadFile);

}

?>

can someone help me add a script which will rename the file name of image?

preferably the new name will be a name which will be written in a TextInput component in the swf.

alternatively - random number.

thanks

ehud

Link to comment
https://forums.phpfreaks.com/topic/82536-rename-image-in-php/
Share on other sites

try:

 

<?php

  if (is_uploaded_file($_FILES['Filedata']['tmp_name']))    {
     $name = $_POST['name'];
     $uploadDirectory = "uploads/";
     $uploadFile = $uploadDirectory . basename($_FILES['Filedata']['name']);
     copy($_FILES['Filedata']['tmp_name'], $uploadFile);
     $path_parts = pathinfo($uploadfile);
     $extension = $path_parts['extension'];
     $uploadFilename = $uploadDirectory . $name" . "$extension;
     rename($uploadFile, $uploadFilename);
  }
?>

Link to comment
https://forums.phpfreaks.com/topic/82536-rename-image-in-php/#findComment-419597
Share on other sites

dear cooldude832

i use the following script in flash (using fileReference:

//import the FileReference Object
import flash.net.FileReference;
//initial settings - since no upload file type selet yet user cannot upload a file
uploadButn.enabled = false;
browseButn.enabled = true;
//create a new FileReference object
var fileRef:FileReference = new FileReference();
//create a listener object for FileReference events
var fileRefListener:Object = new Object();
//create a listener object for comboBox events
var myComBoxListener:Object = new Object();

var isDefault:Boolean = false;

//a small function to redraw (reset) the progress bar
function reDrawPB (pb, xCor, yCor) {
_root.destroyObject(pb);
_root.createObject("ProgressBar",pb,0);
   	_root.progressBar.move(xCor,yCor);
}


//===================== COMBO BOX EVENT HANDLER =====================//

myComBoxListener.change = function(obj) {
fileType = obj.target.selectedItem.label

switch (fileType) {
	case "Images": 
		fileDescription = "Images";
		fileExtension = "*.jpg; *.jpeg; *.gif; *.png";
		reDrawPB ("progressBar", -177, 18);
		break;
	case "Text Files":
		fileDescription = "Text Files";
		fileExtension = "*.txt; *.rtf; *.doc";
		reDrawPB ("progressBar",-177, 18);
		break;
	case "Zip Files":
		fileDescription = "Zip File";
		fileExtension = "*.zip";
		reDrawPB ("progressBar", -177, 18);
		break;
	default:
		isDefault = true;
		trace (isDefault);
		break;
}

status_txt.vPosition = status_txt.maxVPosition;

if (isDefault == true) {
	//if user select the file type option it will clear the text area
	status_txt.text="";
	browseButn.enabled = false;
	isDefault = false;
		}else {
	status_txt.text = fileDescription + ' ' + '('+fileExtension+')'+'\n';
	browseButn.enabled = true;
}
}
//apply object listener to the file reference object
fileType.addEventListener("change", myComBoxListener);

//===================== FILEREFERENCE EVENT HANDLER =====================//

//When user selects a file from the file-browsing dialog box, 
//the onSelect() method is called, and passed a reference to the FileReference object
fileRefListener.onSelect = function (fileRef:FileReference):Void {
fileDescription = "Images";
fileExtension = "*.jpg; *.jpeg; *.gif; *.png";
reDrawPB ("progressBar",-177, 18);
uploadButn.enabled = true;
reDrawPB("progressBar", -177, 18);
status_txt.vPosition = status_txt.maxVPosition;	
status_txt.text += "File is selected to upload \n";
status_txt.vPosition = status_txt.maxVPosition;
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "-------------------------------FILE DETAILS------------------------------- \n";
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "File Size: " + fileRef.size + " bytes" + '\n';
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "File Type: " + fileRef.type + '\n';
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "File Name: " + fileRef.name + '\n';
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "Date Created: " + fileRef.creationDate + '\n';
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "Date Modified: " + fileRef.modificationDate + '\n';
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "--------------------------------------------------------------------------------- \n";
}

//When user dismiss the file-browsing dialog box, 
//the onCancel() method is called, and passed a reference to the FileReference object
fileRefListener.onCancel = function (fileRef:FileReference):Void {
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text +="User terminated file upload. \n";
}

//When the file upload/download process started, 
//the onOpen() method is called, and passed a reference to the FileReference object
fileRefListener.onOpen = function (fileRef:FileReference):Void {
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text +="Opening file " + fileRef.name + '\n';	
}

//The onProgress() method is called periodically during the file upload operation
fileRefListener.onProgress = function (fileRef:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
//setting the status bar function
progressBar.mode = "manual";
progressBar.setProgress(bytesLoaded, bytesTotal);
}

//When the file upload/download operation is successfully complete, 
//the onComplete() method is called, and passed a reference to the FileReference object
fileRefListener.onComplete = function (fileRef:FileReference):Void {
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "The "+fileRef.name + " has been uploaded.\n";
reDrawPB ("progressBar",-177, 18);
filename=fileRef.name;
//_root.progressBar._x=-600;
//_root.progressBar._y=-50;
uploadButn._x=-150;
//_root.confirm.text="לחץ לשמירת התמונה והעלאתה מהשרת"; 
_root.confirm.text="לחץ לשמירת התמונה והעלאתה מהשרת"; 

ok._x=862;
ok._y=_root.thisy+132;
status_txt._x=-410;
_root.frame._y=_root.thisy+132;
//upload is now complete, disable the upload & browse button
uploadButn.enabled = false;
}

//********************************* ERROR EVENT HANDLING *********************************//

//This method will be called if and only if an upload fails because of an HTTP error
fileRefListener.onHTTPError = function (fileRef:FileReference, error:Number) {
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text +="HTTP error: with " + fileRef.name + " :error #" + error + '\n';
}

//This method will be called if and only if a file input/output error occur
fileRefListener.onIOError = function (fileRef:FileReference) {
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text +="HTTP error: with " + fileRef.name + '\n';
}

//This method will be called if and only if an upload fails because of a security error
//9 out of 10 time this error occus is because of the user Flash8 player security settings
fileRefListener.onSecurityError = function (fileRef:FileReference, errorString:String) {
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text +="Security error: with " + fileRef.name + " : " + errorString + '\n';
}
//****************************************************************************************//

//attach Listener to the FileReference Object
fileRef.addListener(fileRefListener);

//button event for the browse button
browseButn.clickHandler = function () {
_root.warning.text="";

//The browse function is the key, coz it displays a file-browsing dialog box
//in which the user can select a local file to upload
fileDescription = "Images";
fileExtension = "*.jpg; *.jpeg; *.gif; *.png";
fileRef.browse([{description: fileDescription, extension: fileExtension}]);

}

//Button event for the upload button
uploadButn.clickHandler = function () {
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text +="Attempting to upload " + fileRef.name + '\n';
if(fileRef.size>200000){
	_root.warning.text="גודל מקסימלי לתמונה 200 קילובייט - גודל התמונה שבחרת    "+(fileRef.size/1000)+"   קילובייט";
	_root.browseButn._x=807;
	_root.browseButn._y=108;
	_root.frame._y=128;
	_root.uploadButn._x=1200;
	_root.confirm.text="בחרו תמונה אחרת שגודלה פחות מ 200 קילובייט"
	return;
}
//upload the file to the PHP script on the server
//put your domain in the upload() method
fileRef.upload("http://www.tovale.co.il/upload.php");
}

 

can you add the neccessary script?

 

Link to comment
https://forums.phpfreaks.com/topic/82536-rename-image-in-php/#findComment-419911
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.