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.

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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.

 

 

 

Link to comment
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.