Jump to content

Trouble with renaming and uploading...not using DB


forumnz

Recommended Posts

I am having trouble with the concept of a script that a user can browse a gif/jpg image on their comp. then write a new image name, then click upload. The image then is uploaded under the new name to the mo_images directory.

 

Help is much appreciated please?

 

Thanks,

 

Sam.

Do you want the user to be able to browse the file system directly from the browser, or click a button that says '...browse' and get a pop-up window to browse the file system? You want the user to rename the image after they upload it to the server? Why don't they just rename it before they upload it?

uploads a file and renames the flle to a random number ok.

 

good luck

 

upload.php

 

<?php

//random number

$num="123456";
$num=rand(000000,111111);

// directory path.

$uploaddir = 'upload_new/';

// get the dir to send file to and the file name.

$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

$file=$uploadfile;

$ext = substr($file, -4);

$uploadfile=$uploaddir.$num.$ext;

@rename($file,$uplaodfile);

// if all the conditions are correct send the file to the directory.

if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)){

// success echoed

echo " <font color='red'>File is valid, and was successfully uploaded.</font>";

}else {

//unsuccesfull echoed

echo "<font color='red'>File was unsuccesful sorry</font>";

}

// show the form.
   
echo"
<form enctype='multipart/form-data' action='upload.php' method='POST'>
   
<input type='hidden' name='MAX_FILE_SIZE' value='30000000000000000000000'>

send this file <input name='userfile' type='file' >
    
<input type='submit' name='submit' value='Send File'>

</form>";

?>

not tested ok.

 

<?php


// directory path.

$uploaddir = 'upload_new/';

// get the dir to send file to and the file name.

$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

$file_name=$uploadfile;

@rename($file_name,$uplaodfile);

// if all the conditions are correct send the file to the directory.

if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)){

// success echoed

echo " <font color='red'>File is valid, and was successfully uploaded.</font>";

}else {

//unsuccesfull echoed

echo "<font color='red'>File was unsuccesful sorry</font>";

}

// show the form.
   
echo"
<form enctype='multipart/form-data' action='upload.php' method='POST'>
   
<input type='hidden' name='MAX_FILE_SIZE' value='30000000000000000000000'>
please provide a file name:
<br>
send this file <input name='file_name' type='text' >
<br>

send this file <input name='userfile' type='file' >
    
<input type='submit' name='submit' value='Send File'>

</form>";

?>

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.