Jump to content

Recommended Posts

Hi i have a simple triple upload file script that upload files with its own name it works fine but what i want is to be able to specify the name of the image like file 1 give name (blue) file 2 name (tree) file 3 name (sky)

<?php

//set where you want to store files

//in this example we keep file in folder upload

//$HTTP_POST_FILES['ufile']['name']; = upload file name

//for example upload file name cartoon.gif . $path will be upload/cartoon.gif

$path1= "images/posters/".$_FILES['ufile']['name'][0];

$path2= "images/posters/".$_FILES['ufile']['name'][1];

$path3= "images/posters/".$_FILES['ufile']['name'][2];





//copy file to where you want to store file

copy($_FILES['ufile']['tmp_name'][0], $path1);

copy($_FILES['ufile']['tmp_name'][1], $path2);

copy($_FILES['ufile']['tmp_name'][2], $path3);



//$HTTP_POST_FILES['ufile']['name'] = file name

//$HTTP_POST_FILES['ufile']['size'] = file size

//$HTTP_POST_FILES['ufile']['type'] = type of file

echo "File Name :".$_FILES['ufile']['name'][0]."<BR/>";

echo "File Size :".$_FILES['ufile']['size'][0]."<BR/>";

echo "File Type :".$_FILES['ufile']['type'][0]."<BR/>";

echo "<img src=\"$path1\" width=\"150\" height=\"150\">";

echo "<P>";



echo "File Name :".$_FILES['ufile']['name'][1]."<BR/>";

echo "File Size :".$_FILES['ufile']['size'][1]."<BR/>";

echo "File Type :".$_FILES['ufile']['type'][1]."<BR/>";

echo "<img src=\"$path2\" width=\"150\" height=\"150\">";

echo "<P>";



echo "File Name :".$_FILES['ufile']['name'][2]."<BR/>";

echo "File Size :".$_FILES['ufile']['size'][2]."<BR/>";

echo "File Type :".$_FILES['ufile']['type'][2]."<BR/>";

echo "<img src=\"$path3\" width=\"150\" height=\"150\">";



///////////////////////////////////////////////////////



// Use this code to display the error or success.



$filesize1=$_FILES['ufile']['size'][0];

$filesize2=$_FILES['ufile']['size'][1];

$filesize3=$_FILES['ufile']['size'][2];



if($filesize1 && $filesize2 && $filesize3 != 0)

{

echo "We have recieved your files";

}



else {

echo "ERROR.....";

}



//////////////////////////////////////////////



// What files that have a problem? (if found)



if($filesize1==0) {

echo "There're something error in your first file";

echo "<BR />";

}



if($filesize2==0) {

echo "There're something error in your second file";

echo "<BR />";

}



if($filesize3==0) {

echo "There're something error in your third file";

echo "<BR />";

}



?>

Link to comment
https://forums.phpfreaks.com/topic/214495-rename-simple-upload-file/
Share on other sites

I would use move_uploaded_file().

 

But the answer to your question is:

$path1= "images/posters/blue.jpg";

$path2= "images/posters/tree.jpg";

$path3= "images/posters/sky.jpg";

 

do u mean replace this

 

$path1= "images/posters/".$_FILES['ufile']['name'][0];

$path2= "images/posters/".$_FILES['ufile']['name'][1];

$path3= "images/posters/".$_FILES['ufile']['name'][2];

with what u sent me or put that next to it??

For simplicities sake, I think you should use the simpleImage class.

 


if( isset($_POST['submit']) ) {
      include('SimpleImage.php');
      $image = new SimpleImage();
      $image->load($_FILES['uploaded_image']['tmp_name']);
      $image->resize(150,150);
      $image->save($filename);
   }

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.