Jump to content

How to replace a $_FILE global name for a variable value.


co.ador

Recommended Posts

The Global $_FILE field value is

<?php basename($_FILES['file']['name'] ?>

 

the variable value is

 

<?php $newname = $id . ".jpg" ?>

 

The Field "file" is carry a value of a picture for instance penguin.jpg and then I want to replace that name for $id . ".jpg" to make a new name for the file and replace it for the id fo the product like 34.jpg.

 

 

I am working on an upload file script so far is moving the file but with the original name and I trying to make a new and rename it to the id of the product

 

the script is as below and so far is inserting the original name of the file in $uploaddir . basename($_FILES['file']['name']  instead I am looking for something like $uuploaddir . $newname which #newname is equal to $id. "jpg"

 

<?php
// $newname = $id . ".jpg";
$uploaddir = '/home3/ny/public_html/your/inventory_images/';
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "File was not uploaded\n";
}
?>

 

Any suggestions?

 

so far as I said the  existing code is uploading but with the original name file.

@MGA

 

ok, i can see how you did directly.

 

now, When i submitted the form it print "File is valid, and was successfully uploaded" but when I go to the inventory_images I don't find neither the orginal file name or the renamed one which would be 194.jpg which was the id created this time. I have the script set up to echo the $id variale after form has submitted but I don't see the file.

MGA never mind it was inserting all this time even before the thing is I was using $id = SESSION['user_id']; and I needed $product_id = $_POST['product_id'];

 

Sorry for the inconvenience.

 

Thank you for your post.

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.