Image upload and overwrite

Started by codreanuionut, April 20, 2016, 06:30:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bhast2

#6
well here is a start

It is a the basic code to make an upload page you will have to add html code and all that good stuff

<?php

$target_path 
$_SERVER['DOCUMENT_ROOT']."/test/";

$target_path $target_path basename$_FILES['uploadedfile']['name']); 

  
$c=1;
  while (
file_exists($target_path))
  {
   
$target_path substr($target_path 0strrpos($target_path".")).$c.substr($target_pathstrrpos($target_path"."));
   
$c++;
  }
//$target_path will now be unique file name  

?>


Here is one with checks it might need tweaking for your liking and of course you would have to theme it

<?php
if ($userfile_size >250000)
{
$msg=$msg."Your uploaded file size is more than 250KB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>";
$file_upload="false";}

if (!(
$userfile_type =="image/pjpeg" OR $userfile_type=="image/gif")){$msg=$msg."Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>";
$file_upload="false";}

$add="upload/$userfile_name"// the path with the file name where the file will be stored, upload is the directory name.

if (file_exists("upload/" $_FILES["userfile"]["name"]))
{
echo 
$_FILES["userfile"]["name"] . " already exists. ";
}

if(
move_uploaded_file ($userfile$add)){
// do your coding here to give a thanks message or any other thing.

}else{echo "Failed to upload file Contact Site admin to fix the problem";}

?>

codreanuionut

Quote from: bhast2 on April 21, 2016, 04:47:03 AM
Quote from: codreanuionut on April 21, 2016, 01:18:09 AM
Yes, i know that.. but i can't give ftp access to the whole staff.. i need it to be accessible..

Can't you make it so the only have access to that folder so they can't get into anything else

I can, but not all of them know how to use ftp..

bhast2

Quote from: codreanuionut on April 21, 2016, 01:18:09 AM
Yes, i know that.. but i can't give ftp access to the whole staff.. i need it to be accessible..

Can't you make it so the only have access to that folder so they can't get into anything else

codreanuionut

Yes, i know that.. but i can't give ftp access to the whole staff.. i need it to be accessible..

bhast2

can't you just do this with FTP and then replace the image. Just have the image file as the same name and it will overwrite it

codreanuionut

Hi, i made a new style for my torrent tracker, and i inted to change every now and then the
background image, could someone help me out with a simple image upload code, and when i upload it that
the uploaded picture goes and overwrite the current bg picture.. :-?